


*Grimm, Lenz, Peters and Sievert (2019): Demand for Off-Grid Solar Electricity
*September 2019
*Luciane Lenz, Maximiliane Sievert  

*This Dofile reproduces all output of the main paper by section and the corresponding appendices. 


***** Replicants should be sure to change the directory below to the correct folder on your personal computer where the downloaded data is stored*****
***** Furthermore, they must insure to create a folder within the directory named "Output" where the figures and tables will be collected*****
***** In instances of a re-run, delete all of the existing files in the Output Folder *****


cd 				"DIRECTORY"
use 			"Grimm et al (2019)_WTP Data(publish).dta", clear
net 			install sg97_5,  	from(http://www.stata-journal.com/software/sj12-4) // Install command frmttable for creating descriptive output below










********************************************************************************************************************************
************************************************Section 4.1 & Corresponding Appendix********************************************
********************************************************************************************************************************

//*TABLE 2: DESCRIPTIVE STATISTICS AND BALANCING TEST FOR RANDOMIZED PAYMENT PERIODS*//
*Prepare data Table 2*//
		local 				basiccontrols dum_female_respondent  hoh_years_edu hh_size dum_hoh_farmer share_member_student
		local 				wealth dum_roof_tile tot_ne_exp_month_USD  expen_phone_month_USD energy_exp_month_USD
		local 				lamps lamp_rec Q611a I_exp1_haskitlampSHS 
		
		
		*Clean up variable names*//
		label var 		date 					"Day count"
		label var 		Intro_D 				"Community"
		label var 		dum_female_respondent  	"Female respondent"
		label var 		hoh_years_edu 			"Head of HH years of education"
		label var 		hh_size 				"HH size"
		label var 		dum_hoh_farmer 			"Head of HH is a farmer"
		label var 		share_member_student 	"Share of students in HH"
		label var 		dum_roof_tile 			"House with tile roofing"
		label var 		tot_ne_exp_month_USD	"Monthly non-energy expenditures1"
		label var 		expen_phone_month_USD 	"Monthly phone charging expenditures1"
		label var 		energy_exp_month_USD 	"Monthly energy expenditures1,2"
		label var 		Q611a 					"Owns car battery"
		label var 		lamp_rec 				"Owns rechargeable lamp"
		label var 		I_exp1_haskitlampSHS	"Owns solar kit"
		
		
*Prepare data for reproducing variable means*//
		foreach var 		in `basiccontrols' `wealth' `lamps' {
		foreach 			i in 1 2 3 {
		quietly sum		`var' if I_liq1_scheme==`i' 
		local 				`var'_`i'_m `r(mean)' 					/*Store mean*/	
		local 				lab`var' : variable label `var' 			/*Store label name*/
		quietly sum 		I_liq1_scheme if I_liq1_scheme==`i'	
		local				N`i' `r(N)' 								/*Store number of observations for means for end of table*/
		}
		}
*Prepare data for reproducing p-values of t-tests*// 
		gen					I_liq1_scheme12=1 if I_liq1_scheme==1
		replace				I_liq1_scheme12=2 if I_liq1_scheme==2
		gen 				I_liq1_scheme13=1 if I_liq1_scheme==1
		replace				I_liq1_scheme13=3 if I_liq1_scheme==3
		gen 				I_liq1_scheme23=2 if I_liq1_scheme==2
		replace				I_liq1_scheme23=3 if I_liq1_scheme==3
		
		foreach var 		in `basiccontrols' `wealth' `lamps'{
		foreach 			i in 12 13 23 {
		quietly ttest 		`var', by(I_liq1_scheme`i')				
		local				`var'_`i'_pv `r(p)'						/*store p-values*/
		quietly sum 		I_liq1_scheme`i'
		local				N`i' `r(N)'								/*store number of observations of groups for end of table*/
		}
		}
				
//Output Table 2
		clear mata 
		foreach var 		in `basiccontrols' `wealth' `lamps'  {			
		matrix 			A = (``var'_1_m'', ``var'_2_m'', ``var'_3_m'',``var'_12_pv', ``var'_13_pv', ``var'_23_pv' )
		quietly frmttable 	using Output\Main_Section4.1_Table2.doc, ///
							statmat(A) ///
							sdec(2) ///
							ctitle("", "Mean: Period 1", "Mean: Period 2", "Mean: Period 3", "pval: Period 1 vs. 2", "pval: Period 1 vs. 3", "pval: Period 2 vs. 3") ///
							rtitles(`lab`var'') ///
							title("Table 2: Descriptive statistics and balancing test for randomized payment periods") ///
							append //
		}	
		matrix				A= (`N1', `N2', `N3', `N12', `N13', `N23')
		
		quietly frmttable 	using Output\Main_Section4.1_Table2.doc, ///
							statmat(A) ///
							sdec(0) ///
							rtitles("N") ///
							ctitle("", "Mean: Period 1", "Mean: Period 2", "Mean: Period 3", "pval: Period 1 vs. 2", "pval: Period 1 vs. 3", "pval: Period 2 vs. 3") ///
							append /// 
							note(Note: *** p<0.01 ** p<0.05 * p<0.1 denote statistical significance. Expenditures are in USD. 1 The values are bottom and top coded at 2 percent and 98 percent of the distribution respectively to eliminate outliers. 2 Including expenditures on kerosene dry-cell batteries and candles; we excluded expenditures for charcoal and firewood since the services for which these fuels are used (cooking and ironing) are not replaceable by solar kits; for those 26 households that own a rechargeable lamp we did not elicit expenditures for recharging the lamp.)
		*Drop unneccessary variables *// 
		drop 				I_liq1_scheme1* I_liq1_scheme2*
		
			
			
//APPENDIX E Table E.1: SAVING POTENTIALS OF SOLAR KITS
*Prepare data Table E.1*
		*We define the following replacement factors: 
		foreach 			v in Kit1 Kit2 {
		gen 				rf_candles_`v'=		0.75
		gen					rf_bat_light_`v'=	0.75
		gen					rf_ker_light_`v'=	0.75
		}
		foreach 			v in Kit2 Kit3 {
		gen 				rf_phone_`v'=		1.00
		}
		gen					rf_phone_Kit1=		0.00
		gen					rf_bat_radio_Kit1=	0.00
		gen					rf_bat_radio_Kit2=	0.75
		gen					rf_bat_radio_Kit3=	1.00
		gen					rf_candles_Kit3=	1.00
		gen					rf_bat_light_Kit3=	1.00
		gen					rf_ker_light_Kit3=	1.00

		* Generate sum of savings potential using replacement factors*//
		foreach 			val in Kit1 Kit2 Kit3 {
		gen 				savings_`val'=		(expen_phone_month_USD 	* rf_phone_`val') ///
											+	(candle_exp_month_USD 	* rf_candles_`val') ///
											+	(expen_bat_light_USD 	* rf_bat_light_`val') ///
											+ 	(expen_pet_light_USD 	* rf_ker_light_`val') ///
											+ 	(expen_bat_rad_USD 		* rf_bat_radio_`val')
		label var 			savings_`val' "Monthly savings potentials `val' using replacement factors"
		}

		* Generate total expenditure quintiles*//
		xtile 									expenditure_quintiles= tot_ne_exp_month_USD, nq(5)	
		label var expenditure_quintiles		"Total expenditure quintiles"
		
		* Generate energy savings quintiles*//
		foreach			val in Kit1 Kit2 Kit3 {
        xtile				savings_quintiles_`val'= savings_`val', nq(5)
		label var			savings_quintiles_`val' "Energy Savings from Kit `Kit' quintiles"
        } 
		
		* Generate amortization periods using expenditure means*//
		foreach 			val in Kit1 Kit2 Kit3 {
		egen 				help2_`val'=		mean(savings_`val')
		gen 				amortization_`val'= Marketprice_`val'/help2_`val'
		label var 			amortization_`val' "Amortization months Kit `val' using means"
		}
				
		* Generate amortization periods using total expenditure means by quintiles*// 
		foreach 			val in Kit1 Kit2 Kit3 {
		foreach 			quin in 1 2 3 4 5 {
		egen 				savings_`val'_`quin'= mean(savings_`val') if expenditure_quintiles==`quin'
		gen 				amortization_`val'_`quin'= Marketprice_`val'/savings_`val'_`quin'
		label var 			amortization_`val'_`quin' "Amortization months `val' total expenditures quintile `quin' "
		}
		}		

		* Generate amortization periods using energy saving quintiles*//
		foreach 			val in Kit1 Kit2 Kit3 {
		foreach 			quin in 1 2 3 4 5 {
		egen 				energysavings_`val'_`quin'= mean(savings_`val') if savings_quintiles_`val'==`quin'
		gen 				saving_amortization_`val'_`quin'= Marketprice_`val'/energysavings_`val'_`quin'
		label var 			saving_amortization_`val'_`quin' "Amortization months `val' energy saving quintile `quin'"
		}
		}

		
		* USING INDIVIDUAL VALUES*// 
		* Generate amortization periods using individual household expenditures 
		foreach 			val in Kit1 Kit2 Kit3 {
		gen 				amortization_`val'_indiv= Marketprice_`val'/savings_`val'
		label var 			amortization_`val'_indiv "Amortization months `val'individual"
		}	
		
		*generate amortization periods using total expenditure means by quintiles 
		foreach 			val in Kit1 Kit2 Kit3 {
		foreach 			quin in 1 2 3 4 5 {
		gen 				amortization_`val'_`quin'_indiv= Marketprice_`val'/savings_`val' if expenditure_quintiles==`quin'
		label var 			amortization_`val'_`quin'_indiv "Indiv. values: Amortization months `val' total expenditures quintile `quin' "
		}
		}		

		*generate amortization periods using energy saving quintiles 
		foreach 			val in Kit1 Kit2 Kit3 {
		foreach 			quin in 1 2 3 4 5 {
		gen 				saving_amortization_`val'_`quin'_indiv= Marketprice_`val'/savings_`val' if savings_quintiles_`val'==`quin'
		label var 			saving_amortization_`val'_`quin'_indiv "Indiv. valuesAmortization months `val' energy saving quintile `quin'"
		}
		}

*Output Table E.1 from the appendix *//
		foreach			val in Kit1 Kit2 Kit3 {
		local 				p_`val'		expen_phone_month_USD 	rf_phone_`val'
		local 				c_`val'		candle_exp_month_USD 	rf_candles_`val'
		local 				bat_`val'	expen_bat_light_USD 	rf_bat_light_`val' 
		local 				pet_`val'	expen_pet_light_USD 	rf_ker_light_`val'
		local 				ba_`val'	expen_bat_rad_USD 		rf_bat_radio_`val'
		local				sav_`val' 	savings_`val'
		local				am_`val' 	amortization_`val'_indiv
		asdoc 				sum `p_`val'' `c_`val'' `bat_`val'' `pet_`val'' `ba_`val'' `sav_`val'' `am_`val'' , save(Output\Appendix_TableE1.doc) ///
																										append /// 
																										label /// 
																										dec(2) ///
																										title(Table E.1: Saving potentials `val') /// 
																										stats(mean)
		asdoc				,save(Output\Appendix_TableE1.doc) 	append ///
																		text(Sources: Expenditures data from own data set. RF abbreviates replacement factor /* The amortization period is calculated using means. Amortization periods calculated based individual household values are substantially longer.*/
																		
		}

		
																		
		*Drop unneccessary variables *
		drop	savings_Kit1_1 savings_Kit1_2 savings_Kit1_3 savings_Kit1_4 savings_Kit1_5 savings_Kit2_1 savings_Kit2_2 savings_Kit2_3 savings_Kit2_4 savings_Kit2_5 savings_Kit3_1 savings_Kit3_2 savings_Kit3_3 savings_Kit3_4 savings_Kit3_5
		drop	energysavings_Kit1_1 energysavings_Kit1_2 energysavings_Kit1_3 energysavings_Kit1_4 energysavings_Kit1_5 energysavings_Kit2_1 energysavings_Kit2_2 energysavings_Kit2_3 energysavings_Kit2_4 energysavings_Kit2_5 energysavings_Kit3_1 energysavings_Kit3_2 energysavings_Kit3_3 energysavings_Kit3_4 energysavings_Kit3_5


		
//FOOTNOTE: Amortization results for individual values *// - This file also appends the E1 file

		local 				amo_ind 	amortization_Kit1 amortization_Kit2 amortization_Kit3
		
		asdoc				sum `amo_ind',		save(Output\Appendix_TableE1.doc) ///
												append /// 
												label /// 
												dec(2) ///
												title(Footnote: Amortization periods for individual savings values) /// 
												stats(mean)	
												
												
												
																		
												
//MAIN TEXT Section 5.1. (add-on to Section 4.1): Amortization periods for means of quintiles 1 and 5
*Output 
		local				amo_quin1 	amortization_Kit1_1_indiv 		amortization_Kit2_1_indiv 		amortization_Kit3_1_indiv amortization_Kit1_1 		amortization_Kit2_1 		amortization_Kit3_1
		local				amo_quin5	amortization_Kit1_5_indiv 		amortization_Kit2_5_indiv 		amortization_Kit3_5_indiv amortization_Kit1_5 		amortization_Kit2_5 		amortization_Kit3_5
		local				amo_save5   saving_amortization_Kit1_5_indiv 	saving_amortization_Kit2_5_indiv 	saving_amortization_Kit3_5_indiv saving_amortization_Kit1_5 	saving_amortization_Kit2_5 	saving_amortization_Kit3_5
		
		asdoc				sum `amo_quin1', 	save(Output\Main_Section5.1_Amortization_Text.doc) ///
												append /// 
												label /// 
												dec(2) ///
												title(Amortization periods for Total Expenditure Quintile 1) /// 
												stats(mean)
		asdoc				sum `amo_quin5',	save(Output\Main_Section5.1_Amortization_Text.doc) ///
												append /// 
												label /// 
												dec(2) ///
												title(Amortization periods for Total Expenditure Quintile 5) /// 
												stats(mean)
										
												
		asdoc				sum `amo_save5', save(Output\Main_Section5.1_Amortization_Text.doc) ///
												append /// 
												label /// 
												dec(2) ///
												title(Amortization periods for Replaceable Energy Expenditures Quintile 5) /// 
												stats(mean)
	* Drop unnecessary variables * 
		drop 				rf* help*


	
	
//Main Text Section 4.1: PLACE OF ORIGIN OF KITS OWNED PRIOR TO EXPERIMENT  
*Prepare data
		quietly			tab place_kit, gen(place)
		label var place1	"Kigali/major city market"
		label var place2	"World Vision/Care/Ministry"
		label var place3	"Neighbour"
		label var place4	"Specialized vendor"
		label var place5	"Researchers"
		label var place6	"School"

*Output		
		asdoc				sum place1-place6,		save(Output\Main_Section4.1_SumStats_Text.doc) /// 
													append ///
													label ///
													dec(2) ///
													title(Place of origin of kits owned prior to experiment)
													
		asdoc,										save(Output\Main_Section4.1_SumStats_Text.doc) /// 
													append ///
													text(Note that the question is asked to 44 households that currently and/or formerly owned a solar kit. 9 households do not know the place of origin.)
		*Drop
		drop	place1-place6

		
	
	

//Main text Section 4.1: INFORMED ABOUT MARKET PRICE OF KITS 
*Prepare data
		count 				if (I_exp82!=. | I_exp9!=. | I_exp10!=.) & (I_exp1_haskitlampSHS==1 | I_exp2_hadkit==1)
		gen					priceidea_count_kit= `r(N)'
		count 				if I_exp1_haskitlampSHS==1 | I_exp2_hadkit==1
		gen					kitcount= `r(N)'
		count 				if (I_exp82!=. | I_exp9!=. | I_exp10!=.) & (I_exp1_haskitlampSHS==0 & I_exp2_hadkit==0)
		gen					priceidea_count_nokit= `r(N)'
		count 				if (I_exp1_haskitlampSHS==0 & I_exp2_hadkit==0)
		gen					nokitcount= `r(N)'

		label var			priceidea_count_kit 	"N HH with price idea;kit owners"
		label var			priceidea_count_nokit 	"N HH with price idea;no kit owners"
		label var			kitcount				"N HH currently/formerly owning kit"
		label var			nokitcount				"N HH never owned kit"
		
*Output 			
		asdoc				sum priceidea_count_kit kitcount priceidea_count_nokit nokitcount,	save(Output\Main_Section4.1_SumStats_Text.doc) /// 
																								append ///
																								label ///
																								stat(mean) ///
																								title(Number of households that have a price idea prior to experiment, by kit ownership)
		*Drop
		drop	priceidea* *kitcount











********************************************************************************************************************************
******************************************Section 4.3 & Corresponding Appendix *************************************************
********************************************************************************************************************************
*Section 4.2. is below (after section 4.3) as it requires data generated in Section 4.3. 

// In Paper TABLE 4: 	PAYMENT PERIODS AND WILLIGNESS TO PAY 
// Appendix TABLE F.1: DETAILED REGRESSION RESULTS OF TABLE 4
// Appendix TABLE F.2: DETAILED REGRESSION RESULTS OF TABLE 4 FOR RESTRICTED SAMPLE (MODERN ENERGY)

		
*Prepare data for Table5, TableF1, TableF2
		gen 			lb_1_RWF=	3000 			/*lower bound value in RWF (values 3000, 10000, 90000 where mentioned to auction participants)*/
		gen 			lb_2_RWF=	10000
		gen 			lb_3_RWF=	90000
		
		foreach var 	in 1 2 3 {
		gen 			lb_`var'_raw	=	(lb_`var'_RWF*0.1288)/100 		/*calcualte lower bound in USD*/
		gen				lb_`var'_log	=	log(lb_`var'_raw)				/*take log*/
		label var		lb_`var'_log 		"Lower bound `var' (Log)" 	
		drop			lb_`var'_RWF lb_`var'_raw	
		recast 			float lb_`var'_log, force
		}
		
		foreach var 	in 1 2 3 {
		gen				bid`var'_USD_ll	=	bid`var'_USD
		replace			bid`var'_USD_ll	=	lb_`var'_log if bid`var'_USD==. /*lower level bound required for intreg. Set value equal to lowerbound if no bid was made.*/
		recast			float bid`var'_USD_ll bid`var'_USD, force
		label var		bid`var'_USD_ll "Kit `Lower bound for IR regression, Kit `kit'"
		}
		

		
*Output Table4, TableE1
		*Regression and storing
		local controls1 	date i.Intro_D 
		local controls2 	date i.Intro_D dum_female_respondent  	hoh_years_edu hh_size dum_hoh_farmer share_member_student dum_roof_tile tot_ne_exp_month_USD  
		local controls3 	date i.Intro_D dum_female_respondent  	hoh_years_edu hh_size dum_hoh_farmer share_member_student dum_roof_tile tot_ne_exp_month_USD  expen_phone_month_USD 	energy_exp_month_USD Q611a lamp_rec I_exp1_haskitlampSHS 

		foreach kit 		in 1 2 3  {
		foreach val			in 1 2 3 {
		intreg 				bid`kit'_USD bid`kit'_USD_ll ib1.I_liq1_scheme `controls`val'', vce(robust) /*if no bid was made, the lower bound is equal to missing, the higher bound is equal to the lower bound. If a bid was made, both values are the same*/
		predict				bid`kit'_USD`val', ystar(.,lb_`kit'_log)		
		est store 			r`val'_`kit' 


		*TABLE 4
		local				title 				"Table 4: Payment periods and willingness to pay"
		local				file 				"Table4"
		local 				addnote 			"Note: We display coefficients from an IR estimation with robust standard errors. The dependent variable is log of WTP. The base category is a one-week payment period." 
		local				addtext_1			"Communty and Time, YES, Socio-economics, NO, Energy Consumption, NO, Mean WTP 7 days scheme, . "
		local				addtext_2			"Communty and Time, YES, Socio-economics, YES, Energy Consumption, NO, Mean WTP 7 days scheme, . "
		local				addtext_3			"Communty and Time, YES, Socio-economics, YES, Energy Consumption, YES, Mean WTP 7 days scheme, . " /*mean WTP values have to be added manually, as they are predicted and calculated only after this estimation*/


		outreg2 			[r`val'_`kit'] using "Output\Main_Section 4.3_`file'.doc", 	append ///
																							label ///
																							nodepvar ///
																							nocons ///
																							bdec(3) ///
																							stats(coef pval) ///
																							drop(`controls1' `controls2' `controls3') ///
																							ctitle("Kit`kit'") ///	
																							asterisk(pval) ///
																							title("`title'") /// 	
																							addnote(`addnote' The values are bottom and top coded at 2 percent and 98 percent of the distribution respectively to eliminate the effect of outliers. 2 Excluding energy and phone charging expenditures. 3 Including expenditures on kerosene gas batteries candles and charcoal; excluding expenditures on wood and rechargeable lamp charging.) ///
																							addtext(`addtext_`val'') ///
																							eqdrop(lnsigma)


		*TABLE E.1
		local				title 				"Table F.1: Payment periods and willingness to pay"
		local				file 				"TableF1"
		outreg2 			[r`val'_`kit'] using "Output\Appendix_`file'.doc", 		append ///
																							label ///
																							nodepvar ///
																							bdec(3) ///
																							stats(coef pval) ///
																							drop(`controls1') ///
																							ctitle("Kit`kit'") ///	
																							asterisk(pval) ///
																							title("`title'") /// 	
																							addnote(`addnote' 1 The values are bottom and top coded at 2 percent and 98 percent of the distribution respectively to eliminate the effect of outliers. 2 Excluding energy and phone charging expenditures. 3 Including expenditures on kerosene gas batteries candles and charcoal; excluding expenditures on wood and rechargeable lamp charging.) ///
																							addtext(`addtext_`val'') ///
																							eqdrop(lnsigma)
			}
			}
			
			
		
		*SAVE IR-Corrected WTP VALUES 
		*Store IR-adjusted WTP values for upcoming estimations 
		foreach val in 	1 2 3 {
		foreach control in	1 2 3 {
		gen 				LogWTP_Kit`val'_IR_control`control'			=bid`val'_USD`control'							/*use predicted WTP values, predicted under control set 3*/
		replace			LogWTP_Kit`val'_IR_control`control'				=bid`val'_USD if bid`val'_USD!=.				/*replace with real bids if made */
		label var			LogWTP_Kit`val'_IR_control`control'	 		"Log WTP for Kit `bid' (IR-ajusted)"
		}
		}
		
		*take exponent of log values, i.e. create monetary raw values 
		foreach val in 	1 2 3 {
		foreach control in 1 2 3 {
		gen					WTP_Kit`val'_IR_raw_control`control'			=exp(LogWTP_Kit`val'_IR_control`control') 	
		label var 			WTP_Kit`val'_IR_raw_control`control' 			"WTP for Kit `val' in USD (IR-ajusted)"
		}			
		}	
			
		
		
		
			
//Appendix TABLE F.2
*Output repetition with restricted sample of hhs without solar lamp
		preserve
		drop 				if fullsample==0			/*exclude hh with access to modern energy*/

		local controls1 	date i.Intro_D 
		local controls2 	date i.Intro_D dum_female_respondent  	hoh_years_edu hh_size dum_hoh_farmer share_member_student dum_roof_tile tot_ne_exp_month_USD  
		local controls3 	date i.Intro_D dum_female_respondent  	hoh_years_edu hh_size dum_hoh_farmer share_member_student dum_roof_tile tot_ne_exp_month_USD  expen_phone_month_USD 	energy_exp_month_USD Q611a lamp_rec I_exp1_haskitlampSHS 
		
		
		foreach kit 		in 1 2 3  {
		foreach val		in 1 2 3 {
		
		*Regression and storing
		quietly intreg 	bid`kit'_USD bid`kit'_USD_ll ib1.I_liq1_scheme `controls`val'', vce(robust) /*if no bid was made, the lower bound is equal to missing, the higher bound is equal to the lower bound. If a bid was made, both values are the same*/		
		est store 			r`val'_`kit' 
		local				title 	"Table F.2: Detailed regression results of Table 4 restricted to sample without access to modern electricity - Payment periods and willingness to pay"
		local				file 	"TableF2"
		outreg2 			[r`val'_`kit'] using "Output\Appendix_`file'.doc", 			append ///
																							label ///
																							nodepvar ///
																							bdec(3) ///
																							stats(coef pval) ///
																							drop(`controls1') ///
																							ctitle("Kit`kit'") ///	
																							asterisk(pval) ///
																							title("`title'") /// 	
																							addnote(`addnote' 1 The values are bottom and top coded at 2 percent and 98 percent of the distribution respectively to eliminate the effect of outliers. 2 Excluding energy and phone charging expenditures. 3 Including expenditures on kerosene, gas, batteries, candles and charcoal; excluding expenditures on wood and rechargeable lamp charging.) ///
																							addtext(`addtext_`val'') ///
																							eqdrop(lnsigma)
		}
		}
		restore
		

		*Dro
		drop	_est_r* LogWTP_Kit*_IR* bid1_USD1 _est_r1_1 bid1_USD2 _est_r2_1 bid1_USD3 _est_r3_1 bid2_USD1 _est_r1_2 bid2_USD2 _est_r2_2 bid2_USD3 _est_r3_2 bid3_USD1 _est_r1_3 bid3_USD2 _est_r2_3 bid3_USD3 _est_r3_3
			










********************************************************************************************************************************
********************************************************Section 4.2 ************************************************************
********************************************************************************************************************************


//TABLE 3: BIDDING GAME RESULTS* 
*Prepare data Table 3
		//*Generate Bid as share of monthly expenditure using Intreg-adjusted WTP values 
		foreach 	var in 1 2 3 {
		gen 		bid`var'_exp_share			=(bid`var'_USD_raw*100)/total_exp_month_nowood_USD 					if bid`var'_USD_raw!=. & total_exp_month_nowood_USD!=. 
		label var 	bid`var'_exp_share 			"Bid `var' share total monthly expenditures"
		gen 		bid`var'_exp_share_IR		=(WTP_Kit`var'_IR_raw_control3*100)/total_exp_month_nowood_USD 		if WTP_Kit`var'_IR_raw_control3!=. & total_exp_month_nowood_USD!=. 
		label var 	bid`var'_exp_share_IR 		"Bid `var' share total monthly expenditures_IR-adjusted values"
		}
		

		
		//*Generate median WTP values of both mean WTP and mean IR-adjusted WTP 
		foreach 		var in 1 2 3 {
		quietly sum 	bid`var'_USD_raw, detail
		gen				bid`var'_med=`r(p50)'
		quietly sum 	WTP_Kit`var'_IR_raw_control3, detail
		gen				bid`var'_IRmed=`r(p50)'
		quietly sum 	bid`var'_exp_share, detail
		gen				bid`var'_exp_sharemed=`r(p50)'
		quietly sum 	bid`var'_exp_share_IR, detail
		gen				bid`var'_exp_share_IRmed=`r(p50)'
		}
		
		//*FOOTNOTE: alternative calculation share in expenditures
		foreach 		var in 1 2 3 {
		egen 			meanWTP`var'=mean(WTP_Kit`var'_IR_raw_control3)
		label var 		meanWTP`var' "Mean 
		}
		egen 			meanEXP=mean(total_exp_month_nowood_USD)
		quietly sum	total_exp_month_nowood_USD, detail
		gen				medEXP=`r(p50)'
		
		foreach var 	in 1 2 3 {
		gen 			mean_share`var'		=meanWTP`var'/meanEXP
		label var		mean_share`var' 	"Bid Kit`var' as mean share in expend: alternative calculation"
		gen 			median_share`var'	=bid`var'_IRmed/medEXP
		label var		median_share`var' 	"Bid Kit `var' as median share in expend: alternative calculation"
		sum 			mean_share`var'
		sum 			median_share`var'
		}
		
		drop			meanEXP medEXP meanWTP1 meanWTP2 meanWTP3
		
		//*Generate number of observations of bids won and sales made 
		foreach 			var in 1 2 3 {
		count				if winchose`var'	==1 					/*create win count variable*/
		gen					wincount`var'		=r(N)
		label var			wincount`var' 		"N Win Kit `var'"
		count				if dum_sale`var'	==1 					/*create buy count variable*/
		gen					buycount`var'		=r(N)
		label var			buycount`var' 		"N Buy Kit `var'"
		}
		
		foreach 			var	in 1 2 3 { 							/*create locals of values that should appear in descriptive table to use in matrix*/
		foreach 			variable in Q_parti_k`var' Marketprice_Kit`var' bid`var'_USD_raw bid`var'_med WTP_Kit`var'_IR_raw_control3 bid`var'_IRmed bid`var'_exp_share bid`var'_exp_sharemed bid`var'_exp_share_IR bid`var'_exp_share_IRmed wincount`var' buycount`var' {
		quietly sum 		`variable'
		local				`variable' `r(mean)'	
		local				`variable'_sd `r(sd)' 
		local				`variable'_N `r(N)'
		}
		}
		
//Output Table 3
		clear mata 
		matrix Table3 		= (	`Q_parti_k1', 						`Q_parti_k2', 						`Q_parti_k3'\ ///
								`Marketprice_Kit1', 				`Marketprice_Kit2',				`Marketprice_Kit3'\ ///
								`bid1_USD_raw', 					`bid2_USD_raw', 					`bid3_USD_raw'\ ///
								`bid1_USD_raw_sd', 				`bid2_USD_raw_sd', 				`bid3_USD_raw_sd'\ ///
								`bid1_med', 						`bid2_med', 						`bid3_med'\ ///
								`WTP_Kit1_IR_raw_control3', 		`WTP_Kit2_IR_raw_control3', 		`WTP_Kit3_IR_raw_control3' \ ///
								`WTP_Kit1_IR_raw_control3_sd', 	`WTP_Kit2_IR_raw_control3_sd', 	`WTP_Kit3_IR_raw_control3_sd' \ ///
								`bid1_IRmed', 						`bid2_IRmed', 						`bid3_IRmed'\ ///
								`bid1_exp_share', 				`bid2_exp_share', 				`bid3_exp_share'\ ///
								`bid1_exp_share_sd', 				`bid2_exp_share_sd',				`bid3_exp_share_sd'\ ///
								`bid1_exp_sharemed',				`bid2_exp_sharemed',				`bid3_exp_sharemed'\ ///
								`bid1_exp_share_IR', 				`bid2_exp_share_IR', 				`bid3_exp_share_IR'\ ///
								`bid1_exp_share_IR_sd',			`bid2_exp_share_IR_sd',			`bid3_exp_share_IR_sd'\ ///
								`bid1_exp_share_IRmed',			`bid2_exp_share_IRmed',			`bid3_exp_share_IRmed'\ ///								
								`wincount1', 						`wincount2', 						`wincount3'\ ///
								`buycount1', 						`buycount2', 						`buycount3'\ ///
								`Q_parti_k1_N', 					`Q_parti_k2_N', 					`Q_parti_k3_N')
								
		
		
		frmttable 			using Output\Main_Section4.2_Table3.doc, 	statmat(Table3) ///
																		append ///
																		sdec(2) ///
																		title("Table 3: Bidding game outcomes") ///
																		ctitle("", "Kit1", "Kit2", "Kit3") ///
																		rtitle("Respondent participates in bidding game" \ ///
																		"Market price (USD)" \ "Mean bid, bidders only(USD)" \ "sd" \"Median bid, bidders only (USD)" \ ///
																		"Mean bid full sample (USD, IR corrected)" \ "sd" \ "Median bid, bidders only (USD, IR corrected)" \ ///
																		"Mean bid as share of monthly expenditures" \ "sd" \ "Median bid as share of monthly expenditures" \ ///
																		"Mean bid as share of monthly expenditures (IR corrected)" \ "sd" \ "Median bid as share of monthly expenditureso (IR corrected)" \ ///
																		"N Sales in experiment" \ "N contracts effectively signed" \ "Number of observations") ///
																		addrows(Note:  We display standard deviations in parentheses. Values are in USD. 1Values are bottom and top coded at 2% and 98% of the distribution respectively to eliminate the effect of outliers.\ ///
																				2Excluding expenditures on wood and rechargeable lamps. IR-corrected values are predicted using all variables listed in Table 2.\ ///
																				3Means are calculated by averaging over the share of bids in total monthly)
																		
		*drop
		drop wincount* buycount*



//FOOTNOTE: WHY DOES NOT WANT TO PARTICIPATE IN BIDDING
*Output
		foreach 			v in  1 2 3 {
		asdoc				tab Q_whynot_parK`v', 	save(Output\Main_Section4.2_Footnote.doc) /// 
													append ///
													label ///
													dec(2) ///
													title(Footnote: Why does not want to participate in bid `v')
		}		


//MAIN TEXT: SATISFACTION WITH BIDDING 
*Output
		asdoc 			tab Q124b, 			save(Output\Main_Section4.2_Footnote.doc) ///
											fs(10) ///
											append ///
											label ///
											dec(2) ///
											title(Footnote: Reason for unhappiness with bid, full sample)
//Appendix: DECLINE PURCHASE
*Output
		asdoc 			tab sale_fail_all, 	save(Output\Main_Section4.2_Text.doc) ///
											fs(10) ///
											append ///
											label ///
											dec(2) ///
											title(Electronic Appendix: Decline to purchase, by Kit)

																												

//FOOTNOTE: WTP OF RESTRICTED SAMPLE OF MODERN ELECTRICITY OWNERS
*Output MEDIAN AND MEAN
		preserve
		keep if			fullsample==1
		foreach var in 	1 2 3 {
		egen				WTP_restrict`var'= median(WTP_Kit`var'_IR_raw_control3)
		label var			WTP_restrict`var' "Median WTP restricted sample"
		asdoc				sum WTP_restrict`var' WTP_Kit`var'_IR_raw_control3, 			save(Output\Main_Section4.2_Footnote.doc) /// 
																							append ///
																							label ///
																							tzoc ///  
																							title(Footnote: IR-corrected Median and Mean WTP for Kit `var' of restricted sample of no electricity owners) ///
																							stat(mean N) 
		asdoc				, save(Output\Main_Section4.2_Footnote.doc) 					append ///
																							text(The subsample excludes hhs that own a solar kit, solar lamp, or car battery before our experiment) ///
																							fs(7)
		}
		restore
		

		
		
		
//*FIGURE 3: DEMAND FOR SOLAR KITS*//
*Prepare data
		foreach 		val in 1 2 3 {
		cumul 			WTP_Kit`val'_IR_raw_control3, gen(WTP_Kit`val'_IR_raw_control3_cum) /*to graph cumulative uptake*/ /*Note that WTP variable is created in this DOfile after IR regression*/
		replace 		WTP_Kit`val'_IR_raw_control3_cum= (WTP_Kit`val'_IR_raw_control3_cum*-1)+1
		sort 			WTP_Kit`val'_IR_raw_control3_cum 

		sum 			WTP_Kit`val'_IR_raw_control3 if WTP_Kit`val'_IR_raw_control3_cum<=.979  /*to graph 98% uptake value*/
		gen				fx_`val'		= `r(min)'
		quietly sum 	fx_`val'
		local			fx_`val' 		`r(mean)'
		local			fx_`val'_label	= string(`r(mean)')

		gen				lb_`val'_raw  	= exp(lb_`val'_log)
		quietly sum	lb_`val'_raw
		local			lobound_`val' 	`r(mean)' /*to graph lower bound*/
		quietly sum 	Marketprice_Kit`val'
		local			upbound_`val' 	`r(mean)' /*to graph upper bound*/

*Output
		quietly line	WTP_Kit`val'_IR_raw_control3_cum WTP_Kit`val'_IR_raw_control3, 	title(Demand for Kit `val') ///
																							clpattern(line) clcolor(brown) ///
																							ytitle(Uptake (Proportion of Population)) ///
																							xtitle(WTP in USD) ///
																							graphr(c(white)) ///
																							xline(`lobound_`val'', lpattern(dot)) xline(`upbound_`val'', lpattern(dot)) ///
																							text(-0.05 `lobound_`val''  "LB", size(medsmall)) ///
																							text(-0.05 `upbound_`val''  "UB", size(medsmall)) ///
																							text(-0.05 `fx_`val'' "98% uptake at `fx_`val'_label' USD", orientation(vertical) place(n) size(medsmall)) 
 
		graph export 	"Output\Main_Section4.3_Figure3_Kit`val'.png", as(png) replace
		
		*Drop
		drop 			fx_*  lb_*_raw
		}
		
		*Drop 
		drop *med WTP_Kit*_IR_raw_control3_cum 











********************************************************************************************************************************
********************************************************Section 5.1 ************************************************************
********************************************************************************************************************************

//Appendix Table G.1:Summary statistics on pre-experiment solar kit exposure
*Prepare data
		gen				Had_kitposnone=0 	
		replace			Had_kitposnone=1 	if I_exp2_hadkit==1 & ( I_exp4==1 | I_exp4==.)	/*had a positive or missing own experience*/
		gen				Had_kitneg=0
		replace			Had_kitneg=1 		if I_exp2_hadkit==1 & I_exp4==0
	
		
		gen 			experience=. 
		replace			experience=0 		
		replace			experience=1		if I_exp6==1
		replace			experience=2 		if I_exp6==0
		replace			experience=3		if I_exp5==1
		replace			experience=4		if Had_kitneg==1
		replace			experience=5		if Had_kitposnone==1
		replace			experience=6 		if I_exp1_haskitlampSHS==1
		label define 	experience 0 "No kit exposure" 1 "Positive word-of-mouth" 2 "Negative word-of-mouth" 3 "Usage elsewhere" 4 "Negative ownership experience" 5 "Positive/undefined ownership experience" 6 "Current ownership"
		label val 		experience experience
		label var		experience "Experience with kits prior to experiment"
	
		quietly tab 		experience, gen(exp)			

		
		foreach 			variable in exp1 exp2 exp3 exp4 exp5 exp6 exp7 { /*create means of values to be displayed in the table*/
		quietly sum 		`variable'
		local				`variable' 		`r(mean)'	
		}
		

*Output Table G.1
		clear mata 
		matrix TableX 		= (	`exp1'\ ///
								`exp2'\ ///
								`exp3'\ ///
								`exp4'\ ///
								`exp5'\ ///
								`exp6'\ ///
								`exp7')

		
		
		frmttable 			using Output\Appendix_TableG1.doc, 	statmat(TableX) ///
																		append ///
																		sdec(2) ///
																		title("Table G.1: Summary statistics on previous solar kit exposure") ///
																		ctitle("", "Mean") ///
																		rtitle("No kit exposure" \ "Positive word-of-mouth" \ "Negative/neutral word-of-mouth" \ "Usage elsewhere" \ "Negative ownership experience" \ "Positive/undefined ownership experience" \ "Current ownership") ///
																		addrows(Note: The experience proxies are displayed in increasing order, from lowest to highest possible exposure. Households are coded as their highest exposure, i.e. a participant with current solar kit ownership who also heard about solar kits by word-of-mouth is coded as the former.)
																		
																	
//Appendix Table G2: Payment periods, willingness to pay and former solar kit exposure
*Prepare data 
		preserve
		drop 				if I_exp1_haskitlampSHS==1 /*drop hhs that currently own a solarkit*/
		
		local controls3 	date i.Intro_D* dum_female_respondent  hoh_years_edu hh_size dum_hoh_farmer share_member_student dum_roof_tile tot_ne_exp_month_USD expen_phone_month_USD energy_exp_month_USD Q611a lamp_rec I_exp1_haskitlampSHS 


		*Output
		foreach kit 		in 1 2  {
		intreg 			bid`kit'_USD bid`kit'_USD_ll ib1.I_liq1_scheme i.experience  `controls3', vce(robust) /*if no bid was made, the lower bound is equal to missing, the higher bound is equal to the lower bound. If a bid was made, both values are the same*/
		est store 			r_`kit' 
		local 				addnote 			"Note: We display coefficients from an IR estimation with robust standard errors. The dependent variable is log of WTP. The base category for payment period is a one-week payment period and the base category for the exposure proxies is no exposure. We exclude households that currently own a solar kit as the drivers of WTP for a second solar kit is presumably different. We do not run the regression for Kit 3 as former experience with solar kits virtually completely involved only small devices comparable to Kit 1 and 2. " 
		local				addtext				"Communty and Time, YES, Socio-economics, YES, Energy Consumption, YES"

*Output Table G.2
		local				title 					"Table G.2: Payment periods, willingness to pay and former solar kit exposure"
		outreg2 			[r_`kit'] using 		"Output\Appendix_TableG2.doc", append ///
																										label ///
																										nodepvar ///
																										bdec(3) ///
																										stats(coef pval) ///
																										drop(`controls3') ///
																										ctitle("Kit`kit'") ///	
																										asterisk(pval) ///
																										title("`title'") /// 	
																										addnote(`addnote') ///
																										addtext(`addtext') ///
																										eqdrop(lnsigma)
		}
		restore	
		drop 				Had_kit*











********************************************************************************************************************************
********************************************************Section 5.2 ************************************************************
********************************************************************************************************************************

//TABLE 5: COSTS AND BENEFITS OF OFF-GRID ELECTRICTIY PER HOUSEHOLD USING MEDIAN IR-CORRECTED WTP 
*Prepare data Table 6
		foreach var in 	1 2 3 {
		clonevar 			costs`var'		=Marketprice_Kit`var'
		sum 				WTP_Kit`var'_IR_raw_control3, detail
		gen		 			medianbenefits`var'	=`r(p50)'	
		gen 				mediangap`var'		=costs`var' - medianbenefits`var'
		label var			costs`var' 		"Cost"
		label var 			medianbenefits`var' 	"Direct (Median) Benefits reflected in WTP"
		label var			mediangap`var'		"Median - Internal return on investment gap"
		sum 				WTP_Kit`var'_IR_raw_control3, detail
		gen		 			benefits`var'	=`r(mean)'
		gen 				gap`var'		=costs`var' - benefits`var'
		label var 			benefits`var' 	"Direct Benefits reflected in WTP"
		label var			gap`var'		"Mean - Internal return on investment gap"
		}
*Output Table 5
		foreach val in 	1 2 3 {
		sum 				costs`val'
		local 				costs`val' `r(mean)'
		sum 				benefits`val'
		local 				benefits`val' `r(mean)'
		sum 				gap`val'
		local 				gap`val' `r(mean)'
		sum 				medianbenefits`val'
		local 				medianbenefits`val' `r(mean)'
		sum 				mediangap`val'
		local 				mediangap`val' `r(mean)'
		}
		clear mata 
		matrix Table5 		= (`costs1', `costs2', `costs3' \ `benefits1' , `benefits2' , `benefits3' \ `gap1', `gap2', `gap3' \ `medianbenefits1' , `medianbenefits2' , `medianbenefits3' \ `mediangap1', `mediangap2', `mediangap3' ) 
		frmttable 			using Output\Main_Section5.2_Table5.doc, 	statmat(Table5) ///
																		append ///
																		sdec(2) ///
																		title("Table 6: Costs and internalized benefits of off-grid electricity per household") ///
																		ctitle("", "Kit1", "Kit2", "Kit3") ///
																		rtitle("Cost in USD" \ "Mean Direct Benefits in USD (as reflected in WTP)" \ "Mean Internal return on investment gap in USD" \ "Median Direct Benefits in USD (as reflected in WTP)"\ "Median Internal return on investment gap in USD") ///
    																	addrows(Note: IR corrected WTP are used see Table 3.)
*Drop
		drop 				costs* benefits* gap*


//Main text Section 5.2: CALCULATION OF INTERNAL RETURN ON INVESTMENT GAP FOR 20 YEARS LIFESPAN: MEDIAN
*Prepare data	
		gen lifespan_Kit1					= 3
		gen lifespan_Kit2					= 6
		gen lifespan_Kit3					= 4

		foreach val in 1 2 3 {
		gen yr20_replacements_Kit`val'		= 20/lifespan_Kit`val' 										/*number of kits that have to be purchased over 20year period assuming lifespan above*/
		qui sum yr20_replacements_Kit`val'
		replace yr20_replacements_Kit`val'	= `r(mean)'
		gen yr20_costs_Kit`val'			= yr20_replacements_Kit`val' 	* Marketprice_Kit`val'		/*costs all kits over 20years*/
		qui sum WTP_Kit`val'_IR_raw_control3, detail
		dis `r(mean)'
		gen yr20_benefit_Kit`val'			= yr20_replacements_Kit`val' 	* `r(mean)'				/*MEDIAN benefits all kits over 20years*/
		gen year20_gap`val'				= yr20_costs_Kit`val' 		- yr20_benefit_Kit`val'		
		label var year20_gap`val'			"Kit `val' 20 yr. gap"
		}
	

*Output 
		asdoc 				sum year20_gap1 year20_gap2 year20_gap3, 	save(Output\Main_Section5.2_MeanIR_Text.doc) ///
																		dec(2) ///
																		stat(mean) ///
																		label ///
																		title(Table 6: Mean Internal return on investment gap over 20 years period using median)
		*Drop 
		drop yr20_* lifespan* year20*
		
		
		
//Main text Section 5.2: CALCULATION OF INTERNAL RETURN ON INVESTMENT GAP FOR 20 YEARS LIFESPAN: MEANS
*Prepare data	
		gen 		lifespan_Kit1					= 3
		gen 		lifespan_Kit2					= 6
		gen 		lifespan_Kit3					= 4
		foreach kit in 1 2 3 {
		label var 	lifespan_Kit`kit' "Lifespan of Kit `kit' (according to Dassy Enterprise)"
		}
		foreach 	val in 1 2 3 {
		gen 		yr20_replacements_Kit`val'		= 20/lifespan_Kit`val' 										/*number of kits that have to be purchased over 20year period assuming lifespan above*/
		qui sum 	yr20_replacements_Kit`val'	
		replace 	yr20_replacements_Kit`val'		= `r(mean)'
		gen 		yr20_costs_Kit`val'				= yr20_replacements_Kit`val' 	* Marketprice_Kit`val'		/*costs all kits over 20years (number of kits times market price)*/
		qui sum 	WTP_Kit`val'_IR_raw_control3, detail
		dis 		`r(p50)'
		gen 		yr20_benefit_Kit`val'			= yr20_replacements_Kit`val' 	* `r(p50)'				/*MEDIAN benefits all kits over 20years*/
		gen 		year20_gap`val'					= yr20_costs_Kit`val' 		- yr20_benefit_Kit`val'		
		label var 	year20_gap`val'					"Kit `val' 20 yr. gap"
		}

*Output 
		asdoc 				sum year20_gap1 year20_gap2 year20_gap3, 	save(Output\Main_Section5.2_MedianIR_Text.doc) ///
																		dec(2) ///
																		stat(mean) ///
																		label ///
																		title(Main text: Median Internal return on investment gap over 20 years period)		

		*Drop
		drop yr20_* lifespan* year20*








********************************************************************************************************************************
***************************************** Section 6.1 & corresponding Appendices B and C ***************************************
********************************************************************************************************************************

//Appendix B Table B.1: Sales outcomes, by Kit 
*Prepare data 
		gen 			winchose=. 
		label var		winchose "Kit won and theoretically chosen by HH"
		gen 			winchosebuy=.
		label var		winchosebuy "Kit won, chosen and bought by HH"

		foreach var 	in 1 2 3 {
		replace		winchose=`var' if winchose`var'==1
		replace		winchosebuy=`var' if winchosebuy`var'==1
		}
													
	*Variables for summary statistics
	local 			variables winchose decline_purchase_absence decline_purchase winchosebuy //when adding vars, also change matrix columns and rtitles 

	*for gen empty matrix
	local 			j_rows=4		//number of rows 
	local 			k_columns=1	 	//number of stats
	
	*fill matrix with stats
	foreach sample in winchose1 winchose2 winchose3 {
	mat m_`sample' = J(`j_rows',`k_columns',.)

*Output Table 1
	local y=1
	foreach var of varlist `variables' {
					   sum `var' if `sample'==1, d
					   mat m_`sample'[`y',1] = (r(N))
					   local y=`y'+1
		}
		}
		
		mat m_complete=(m_winchose1, m_winchose2, m_winchose3)								
								
		
		frmttable 			using Output\Appendix_TableB1.doc, 	statmat(m_complete) ///
																				replace ///
																				sdec(0) ///
																				title("Table B1: Bidding game outcomes, by Kit") ///
																				ctitle("",  "Kit 1", "Kit 2", "Kit 3") ///
																				rtitle("N wins in experiment" \ ///
																						"N absent at meeting" \ ///
																						"N actively declines to sign contract" \ ///
																						"N effective sales" )		
																				
																						
//TABLE 6: Incidence of declining and default 			
*Prepare data 
		*generate decline variable
		gen decline2=.
		foreach kit in 1 2 3 {
		replace decline2=1 if winchosebuy`kit'==. & winchose`kit'==1
		}
		label var decline2 "HH declines to buy inspite of winning"

		gen 				share_paid_deadline=. 											/*generate outcome variables*/
		label var			share_paid_deadline "Share HH paid within deadline"
		replace 			share_paid_deadline=acc_daily_share_paid7 	if I_liq1_scheme==1 /*take share paid after 7 days*/
		replace 			share_paid_deadline=acc_daily_share_paid42 	if I_liq1_scheme==2
		replace				share_paid_deadline=acc_daily_share_paid151 if I_liq1_scheme==3
			
		gen					Kit_bought=. 
		label var			Kit_bought  "Kit bought by HH"
		foreach var 		in 1 2 3 { 														/*generate categorical variable explaining which kit is bought*/
		replace				Kit_bought=`var' if winchosebuy`var'==1
		}		

		*Create share paid variables
		foreach var in 		share_paid_deadline share_paid5 {
		gen						`var'_0=0		if							inlist(1,winchosebuy1, winchosebuy2, winchosebuy3)
		replace					`var'_0=1 		if `var'==0					& inlist(1,winchosebuy1, winchosebuy2, winchosebuy3)
		gen						`var'_1_74=0	if							inlist(1,winchosebuy1, winchosebuy2, winchosebuy3)
		replace					`var'_1_74=1 	if inrange(`var',1,74)		& inlist(1,winchosebuy1, winchosebuy2, winchosebuy3)
		gen						`var'_75_99=0	if							inlist(1,winchosebuy1, winchosebuy2, winchosebuy3)
		replace					`var'_75_99=1 	if inrange(`var',75,99)		& inlist(1,winchosebuy1, winchosebuy2, winchosebuy3)
		gen						`var'_100=0		if							inlist(1,winchosebuy1, winchosebuy2, winchosebuy3)
		replace					`var'_100=1 	if `var'>99.99 & `var'!=.	& inlist(1,winchosebuy1, winchosebuy2, winchosebuy3)
		}
		label var				share_paid_deadline_100 		"Share that paid 100 percent deadline"
		label var				share_paid_deadline_1_74 		"Share that paid 1-74 percent deadline"
		label var				share_paid_deadline_75_99 		"Share that paid 75-99 percent deadline"
		label var				share_paid_deadline_0 			"Share that paid 0 percent deadline"
		label var				share_paid5_100 				"Share that paid 100 percent monitoring"
		label var				share_paid5_1_74				"Share that paid 1-74 percent monitoring"
		label var				share_paid5_75_99				"Share that paid 75-99 percent monitoring"
		label var				share_paid5_0 					"Share that paid 0 percent monitoring"

		
		
		*generate shares paid in deadline phase and monitoring phase.  
		foreach var 		in share_paid5 share_paid_deadline {
		gen					r_`var'_0 =	1 		if 	`var'==0					
		replace				r_`var'_0 =	. 		if 	r_`var'_0==. & `var'!=. 	
		gen					r_`var'_1_50=1 		if 	inrange(`var', 1, 50)		
		replace				r_`var'_1_50=. 		if 	r_`var'_1_50==. & `var'!=. 
		gen					r_`var'_51_99=1 	if inrange(`var', 51, 99)		
		replace				r_`var'_51_99=. 	if r_`var'_51_99==. & `var'!=.	 
		gen					r_`var'_100 =1 		if 	`var'==100					
		replace				r_`var'_100 =. 		if 	r_`var'_100==. & `var'!=. 
		*label var			r_`var'* "`var' equals RANGE to last value"
		}
		
		*generate average share paid by kit in deadline phase ad monitoring phase.  
		foreach kit in 		1 2 3{
		foreach var 		in share_paid5 share_paid_deadline {
		sum `var' 			if winchosebuy`kit'==1, d
		gen	`var'_mean_`kit'=	 r(mean)
		}
		label var share_paid5_mean_`kit' 			"Share paid Kit `kit' monitoring"
		label var share_paid_deadline_mean_`kit' 	"Share paid Kit `kit' deadline"
		}
			
		local 			variables decline2 
		*for gen empty matrix
		local 			j_rows=1		//number of rows 
		local 			k_columns=1	 	//number of stats

		*fill matrix with stats
		foreach sample in winchose1 winchose2 winchose3 {
		mat m_`sample' = J(`j_rows',`k_columns',.)

		local y=1
		foreach var of varlist `variables' {
					   sum `var' if `sample'==1, d			
					   local `var'_1= r(N)								//number of decliners
					   dis ``var'_1'
					   sum	`sample', d
					   local `var'_2=r(N)								//number of winners
					   dis ``var'_2'
					   gen `var'_aux= (``var'_1'/``var'_2')*100		//gen decliners/winners to get share
					   sum `var'_aux, d
					   mat m_`sample'[`y',1] = (r(mean))
					   local y=`y'+1
					   drop `var'_aux
		}
		}

*Output Table 6 : Decline stats
		mat m_complete=(m_winchose1, m_winchose2, m_winchose3)								
								

		frmttable 			using Output\Main_Section6.1Table6.doc, 	statmat(m_complete) ///
																		replace ///
																		sdec(1) ///
																		title("Table 6: Decline and default shares, by Kit") ///
																		ctitle("",  "Kit 1", "Kit 2", "Kit 3") ///
																		rtitle( "% of winners declining" )
		clear mata 
			
			
		*Add share that paid full price
		sum 	share_paid_deadline_100 	if inlist(1,winchosebuy1, winchosebuy2, winchosebuy3)
		gen		all_dead =`r(mean)'		if winchosebuy`kit'==1
		foreach kit in 1 2 3 {
		sum 	share_paid_deadline_100 	if winchosebuy`kit'==1
		gen		kit`kit'_dead= `r(mean)'
		}

		sum 	share_paid5_100 
		gen		all_moni =`r(mean)'		if inlist(1,winchosebuy1, winchosebuy2, winchosebuy3)
		foreach kit in 1 2 3 {
		sum 	share_paid5_100 			if winchosebuy`kit'==1
		gen		kit`kit'_moni= `r(mean)' 	
		}	
		
		
		asdoc 				sum  all_dead kit1_dead kit2_dead kit3_dead all_moni kit1_moni kit2_moni kit3_moni, save(Output\Main_Section6.1Table6.doc) ///
																						append /// 
																						label /// 
																						dec(2) ///
																						title(Table 6.1: % buyers paying full price) ///
																						stats(mean)	
																	
		drop all_dead kit1_dead kit2_dead kit3_dead all_moni kit1_moni kit2_moni kit3_moni																
																		
		*Add share paid	
		asdoc 				sum share_paid_deadline_mean_1 share_paid_deadline_mean_2 share_paid_deadline_mean_3 share_paid5_mean_1 share_paid5_mean_2 share_paid5_mean_3  , save(Output\Main_Section6.1Table6.doc) ///
																						append /// 
																						label /// 
																						dec(0) ///
																						title(Table 6.1: % of price paid by all buyers) ///
																						stats(mean)	
																		
																															
//Appendix Table B.2: Purchase decline by kit and payment scheme 
	preserve
*Prepare data 	
		tab 	I_liq1_scheme, gen(scheme)
		drop if sale_fail_all==. //exclude if did not decline 
		
		*Variables for summary statistics
		local 			variables scheme1 scheme2 scheme3 

		*for gen empty matrix
		local 			j_rows=3		//number of rows 
		local 			k_columns=1	 	//number of stats

		*fill matrix with stats
		foreach sample in 1 2 3 {
		mat m_winchose`sample' = J(`j_rows',`k_columns',.)

*Output Table B.2
		local y=1
		foreach var of varlist `variables' {
					   sum `var' if `var'==1 & winchose`sample'==1, d
					   mat m_winchose`sample'[`y',1] = (r(N))
					   local y=`y'+1
		}
		}
		
		mat m_complete=(m_winchose1, m_winchose2, m_winchose3)								
								
		
		frmttable 			using Output\Appendix_TableB2.doc, 	statmat(m_complete) ///
																				replace ///
																				sdec(0) ///
																				title("Table B2: Purchase decline and absence, by Kit and payment scheme") ///
																				ctitle("",  "Kit 1", "Kit 2", "Kit 3") ///
																				rtitle("N Payment scheme: 1 week" \ ///
																						"N Payment scheme: 6 weeks" \ ///
																						"N Payment scheme: 5 months" )																						
	restore


		
//Appendix Table B3: Winning favorite kit among buyers and decliners, by kit 
*Prepare data
		*generate mean and median WTP values of IR-adjusted WTP for buyers and decliners 
		foreach 		var in 1 2 3 {
		sum				WTP_Kit`var'_IR_raw_control3 if winchose`var'==1 & winchosebuy`var'==1, d
		local			buy_mean`var' 	=round(r(mean),.01)
		sum				WTP_Kit`var'_IR_raw_control3 if winchose`var'==1 & winchosebuy`var'==1, d
		local			buy_med`var' 	=round(r(p50),.01)
		sum				WTP_Kit`var'_IR_raw_control3 if winchose`var'==1 & winchosebuy`var'==., d
		local			dec_mean`var' 	=round(r(mean),.01)
		sum				WTP_Kit`var'_IR_raw_control3 if winchose`var'==1 & winchosebuy`var'==., d
		local			dec_med`var' 	=round(r(p50),.01)
		local			share_mean`var'=(`dec_mean`var'')/`buy_mean`var''
		local			share_med`var'=(`dec_med`var'')/`buy_med`var''
		}
		
		*gen variable whether prefered kit has been won 
		foreach 		var in 1 2 3 {
		gen				favo_`var'=0 if winchose`var'!=. 
		replace			favo_`var'=1 if winchose==`var' & Q6==`var' & winchose!=.
		}
		gen 			favo_all=0 if winchose!=. 
		replace			favo_all=1 if winchose==Q6
		label var		favo_all "HH won favorite kit"

		*generate if bigger or smaller kit was wanted
		foreach 		var in 1 2 3 {
		foreach 		pref in 1 2 3 {
		gen 			favo_`pref'_win_`var'=0 if favo_`var'==0
		replace			favo_`pref'_win_`var'=1 if winchose==`var' & Q6==`pref' & favo_`var'==0
		}
		}
	
		*generate means
		foreach 		var in 1 2 3 {
		sum 			favo_`var' if winchose!=. & winchosebuy!=.
		local			buy_`var'	=r(mean)
		sum 			favo_`var' if winchose!=. & winchosebuy==.
		local			dec_`var'	=r(mean)
		sum 			favo_`var' if winchose!=. & winchosebuy==. & decline_purchase_absence==.
		local			pres_`var'	=r(mean)
		}
		sum				favo_all 	if winchose!=. & winchosebuy!=.
		local			buy_all		=r(mean)
		sum				favo_all 	if winchose!=. & winchosebuy==. & decline_purchase_absence==.
		local			dec_all		=r(mean)
	

		*Drop
		drop	favo_1 favo_2 favo_3 favo_1_win_1 favo_2_win_1 favo_3_win_1 favo_1_win_2 favo_2_win_2 favo_3_win_2 favo_1_win_3 favo_2_win_3 favo_3_win_3
		
*Output Table B3
		clear mata 
		matrix Table4 		= (	`buy_1', 		`buy_2', 		`buy_3'\ ///
								`pres_1',		`pres_2',		`pres_3'\ ///
								`buy_all',		`buy_all',		`buy_all'\ ///
								`dec_all',		`dec_all',		`dec_all')

								
								
		
		
		frmttable 			using Output\Appendix_TableB3.doc,	 	statmat(Table4) ///
																		append ///
																		sdec(2) ///
																		title("Table B3: Winning of favorite kit among buyers and decliners, by kit") ///
																		ctitle("", "Kit 1", "Kit 2", "Kit 3") ///
																		rtitle(	"Share winning favorite among buyers" \ ///
																				"Share winning favorite among decliners present at meeting"\ ///
																				"Share winning favorite all buyers" \ ///
																				"Share winning favorite all decliners")

																				
																				
//Appendix Table B4: Share of decliners versus buyers winning prefered kit, by kit  
*Output Table B4
		clear mata 
		matrix Table4 		= (	`buy_mean1', 						`buy_mean2', 						`buy_mean3'\ ///
								`buy_med1', 						`buy_med2', 						`buy_med3'\ ///
								`dec_mean1', 						`dec_mean2', 						`dec_mean3'\ ///
								`dec_med1', 						`dec_med2', 						`dec_med3'\ ///
								`share_mean1',						`share_mean2',						`share_mean3'\ ///
								`share_med1',						`share_med2',						`share_med3')
								
								
		
		
		frmttable 			using Output\Appendix_TableB4.doc,	 	statmat(Table4) ///
																		append ///
																		sdec(2) ///
																		title("Table B4: Bid of decliners versus buyers, by kit ") ///
																		ctitle("", "Kit 1", "Kit 2", "Kit 3") ///
																		rtitle(	"Mean bid among buyers" \ ///
																				"Median bid among buyers" \ ///
																				"Mean bid among decliners" \ ///
																				"Median bid among decliners"\ ///
																				"Increase in percent (decliners vs buyers) mean"\ ///
																				"Increase in percent (decliners vs buyers) median")
																				
//Appendix Table B5: Drivers of decline 
*Prepare data 	
		rename 	Q120a_USD Q120_USD_1
		rename 	Q120b_USD Q120_USD_2
		rename 	Q120c_USD Q120_USD_3
		
		preserve 
		
		drop if 	winchose==. //drop those that do not win 
		
		*generate variable among winners whether decline or not
		gen 		decline=0 if winchose!=.
		replace 	decline=1 if winchose!=. & winchosebuy==. 
		
		*generate bid and price drawn variable over all kits using the kit that was actullay won
		gen 		WTP=. 
		gen 		Pricedrawn=. 
		foreach 	var in 1 2 3 {
		replace	 	WTP=WTP_Kit`var'_IR_raw_control3 	if winchose==`var'
		replace	 	Pricedrawn=Q120_USD_`var' 			if winchose==`var'
		}

	
		*Regression and storing
		tab Intro_D, gen(vill)
		tab winchose, gen(winchosedum)
		tab I_liq1_scheme, gen(liq_scheme)

		local controls2 	date i.Intro_D dum_female_respondent hoh_years_edu hh_size dum_hoh_farmer share_member_student dum_roof_tile tot_ne_exp_month_USD 
		local controls3 	expen_phone_month_USD 	energy_exp_month_USD Q611a lamp_rec I_exp1_haskitlampSHS 

		reg					decline 	favo_all WTP Pricedrawn  i.I_liq1_scheme `controls2' `controls3' i.winchose if winchose!=., vce(cluster Intro_D) //here use bid for the kit that the hh has won and the price drawn also for the kit that was won and include dummy on which type was won in regression 
		est store 			decline
		regress				decline 	favo_all WTP Pricedrawn i.I_liq1_scheme `controls2' `controls3' if winchose==1, vce(cluster Intro_D) 
		est store 			declineKit1
		regress				decline 	favo_all WTP Pricedrawn i.I_liq1_scheme `controls2' `controls3' if winchose==2, vce(cluster Intro_D) 
		est store 			declineKit2
	
*Output Table B5
		local				title 	"Table B5: Drivers of decline"		
		local 				addnote "Note: *** p<0.01, ** p<0.05, * p<0.1 denote statistical significance. We display results from a Linear Probability Model. The sample is restricted to the winners of the three kits. The outcome variable is a binary variable taking the value one for purchase decline. The base category for payment period is one week. The base category for Kit won is Kit 1. We control for community and day count. Standard errors are robust to heteroscedasticity and serial-correlation within communities. Monthly energy expenditures exclude expenditures on wood and rechargeable lamp charging." 
		outreg2 			[decline declineKit1 declineKit2] 	using "Output\Appendix_TableB5.doc", 	replace dec(3) drop(i.Intro_D date) stats(coef pval) label nodepvar asterisk(pval) title("`title'") addnote(`addnote') 
		
		
		restore																					
												
																		
//Appendix Table C.1 Propensity to pay, by kit and payment period																		
*Prepare data		
		
		*Variables for summary statistics
		local 			variables r_share_paid_deadline_0 r_share_paid_deadline_1_50 r_share_paid_deadline_51_99 r_share_paid_deadline_100 r_share_paid5_0 r_share_paid5_1_50 r_share_paid5_51_99 r_share_paid5_100

		*for gen empty matrix
		local 			j_rows=8		//number of rows 
		local 			k_columns=1	 	//number of stats

		*fill matrix with stats
		foreach sample in winchosebuy1 winchosebuy2 winchosebuy3 {
		mat m_`sample' = J(`j_rows',`k_columns',.)

*Output Table C1. 		
		local y=1
		foreach var of varlist `variables' {
					   sum `var' if `sample'==1, d
					   local `var'_1= r(N)
					   dis ``var'_1'
					   sum	`sample', d
					   local `var'_2=r(N)
					   dis ``var'_2'
					   gen `var'_aux= (``var'_1'/``var'_2')*100
					   sum `var'_aux, d
					   mat m_`sample'[`y',1] = (r(mean))
					   local y=`y'+1
					   drop `var'_aux
		}
		}
		
		mat m_complete=(m_winchosebuy1, m_winchosebuy2, m_winchosebuy3)								
								

		frmttable 			using Output\Appendix_TableC1.doc, 			statmat(m_complete) ///
																					sdec(1) ///
																					title("Table C.1: Propensity to pay, by kit and payment period") ///
																					ctitle("",  "Kit 1", "Kit 2", "Kit 3") ///
																					rtitle( "DL: Paid 0 %" \ ///
																							"DL: Paid 1-50 %" \ ///
																							"DL: Paid 51-99 %" \ ///
																							"DL: Paid 100 %" \	///
																							"M: Paid 0 %" \ ///
																							"M: Paid 1-50 %" \ ///
																							"M: Paid 51-99 %" \ ///
																							"M: Paid 100 %" ) ///
																					append
																			
		clear mata 
		
		*drop
		drop r_share_*
		

//Appendix Table C.2.: ANALYSE RELATIONSHIP DEFAULTING AT END OF MONITORING PERIOD AND HH CHARACTERISTICS 
*Prepare data
		foreach var 		in 1 2 3 { 														/*generate gap variable*/
		gen 				gap_kit`var'= 		WTP_Kit`var'_IR_raw_control3 - Q120_USD_`var' if dum_sale`var'==1
		label var 			gap_kit`var' 		"Bid-draw gap Kit `var'" 
		}

		gen					gap_all=	gap_kit1 if winchosebuy1==1							/*generate categorical gap variable*/
		replace 			gap_all=	gap_kit2 if winchosebuy2==1	
		replace 			gap_all=	gap_kit3 if winchosebuy3==1	
		label var 			gap_all 	"Gap Bid-Drawn Price"
		
							
		foreach kit in 1 2 3 {																/*generate dummy for defaulting*/
		gen defaulter`kit'=0 if winchosebuy`kit'==1
		replace defaulter`kit'=1 if share_paid5!=100 & winchosebuy`kit'==1
		label var defaulter`kit' "dummy household defaulted =1"
		}

																							/*generate dummies for how much HH paid*/
		foreach kit in 1 2 {
		gen dum_defaulter`kit'_100=0 if winchosebuy`kit'==1
		replace dum_defaulter`kit'_100=1 if share_paid5==100 & winchosebuy`kit'==1
		label var dum_defaulter`kit'_100 "defaulting dummy: household paid 100%"
		gen dum_defaulter`kit'_10075=0 if winchosebuy`kit'==1
		replace dum_defaulter`kit'_10075=1 if share_paid5<100 & share_paid5>=75  & winchosebuy`kit'==1
		label var dum_defaulter`kit'_10075 "defaulting dummy: household paid between 75 and 100%"
		gen dum_defaulter`kit'_7550=0 if winchosebuy`kit'==1
		replace dum_defaulter`kit'_7550=1 if share_paid5<75 & share_paid5>=50  & winchosebuy`kit'==1
		label var dum_defaulter`kit'_7550 "defaulting dummy: household paid  between 50 and 75%"
		gen dum_defaulter`kit'_5025=0 if winchosebuy`kit'==1
		replace dum_defaulter`kit'_5025=1 if share_paid5<50 & share_paid5>=25  & winchosebuy`kit'==1
		label var dum_defaulter`kit'_5025 "defaulting dummy: household paid  between 25 and 50%"
		gen dum_defaulter`kit'_250=0 if winchosebuy`kit'==1
		replace dum_defaulter`kit'_250=1 if share_paid5<25 & share_paid5>=0  & winchosebuy`kit'==1
		label var dum_defaulter`kit'_250 "defaulting dummy: household paid  between 0 and 25%"
		}
	

		
		*Regression and storing Table C2
		local controls2 	date i.Intro_D dum_female_respondent hoh_years_edu hh_size dum_hoh_farmer share_member_student dum_roof_tile tot_ne_exp_month_USD 
		local controls3 	 expen_phone_month_USD 	energy_exp_month_USD Q611a lamp_rec I_exp1_haskitlampSHS 

		*regression for share paid at end of monitoring with controlset 2+3 including bid made and price-bid-gap
		foreach 			kit in 1 2 {		
		preserve 
		drop				if Kit_bought!=`kit'		
		reg					share_paid5 	WTP_Kit`kit'_IR_raw_control3 gap_kit`kit' ib1.I_liq1_scheme 	`controls2' `controls3', vce(cluster Intro_D)
		est store 			share_paid5_`kit'

*Output Appendix Table C2
		local				title 					"Table C2: Correlates of the payment share by end of monitoring phase(dependent variable)"		

		local 				addnote 				"Note: *** p<0.01, ** p<0.05, * p<0.1 denote statistical significance. We display results from an OLS estimation. The outcome variable is the share effectively paid within the monitoring phase. Monitoring refers to the extended time frame of reminder calls and inclusion of community authority. The base category for payment period is one week. Robust standard errors are clustered on the community level. Monthly energy expenditures exclude expenditures on wood and rechargeable lamp charging." 
		outreg2 			[share_paid5_`kit'] 	using "Output\Appendix_TableC2.doc", 	append ///
																													label ///
																													nodepvar ///
																													bdec(3) ///
																													stats(coef pval) ///
																													drop() ///
																													asterisk(pval) ///
																													title("`title'") /// 
																													sortvar(bid_all gap_all ib1.Kit_bought ib1.I_liq1_scheme ) ///
																													addnote(`addnote') 
		restore
		}


		
			
//Appendix Figure C1
*Prepare data 																																								
		*recode villages, ordered by how many percent paid 100 at end of monitoring, as two graphs in the following cannot be ordered by descending order of the first set of variables only 
		clonevar				Intro_D2=Intro_D
		recode Intro_D2 		(4=1) (7=2) (9=3) (11=4) (13=5) (17=6) (2=7) (10=8) (6=9) (14=10) (15=11) (5=12) (8=13) (3=14) (12=.) (16=.) /*12 and 16 are villages where no household one, so bars are empty*/


		*label village with the number of observations per village 
		foreach village in 	 	1 2 3 4 5 6 7 8 9 10 11 12 13 14 {
		qui sum 				share_paid_deadline if Intro_D2==`village'	
		local					`village'_N `r(N)'
		label define Intro_D2 	`village' "`village' (N=``village'_N')", modify
		label val				Intro_D2 Intro_D2
		} 

		*Replace values by missing if they are completely missing within a village as the zeros are shown in the graph overlaid with other numbers otherwise. 
		foreach var in 		share_paid_deadline_100 share_paid_deadline_0 share_paid_deadline_1_74 share_paid_deadline_75_99 share_paid5_100 share_paid5_0 share_paid5_1_74 share_paid5_75_99 {
		foreach village in 	 	1 2 3 4 5 6 7 8 9 10 11 12 13 14 {
		qui sum 				`var' if Intro_D2==`village'	
		replace 				`var'=. if `r(mean)'==0 &  Intro_D2==`village'	
		}	
		}


		*graphs D1
		local		outcome_dead share_paid_deadline_0 share_paid_deadline_1_74 share_paid_deadline_75_99 share_paid_deadline_100
		local		outcome_mon  share_paid5_0 share_paid5_1_74 share_paid5_75_99 share_paid5_100
		local		title_dead 	"Shares of final price paid by end of deadline by village"
		local		title_mon 	"Shares of final price paid by end of monitoring by village"

		foreach 	phase in dead mon {
		graph bar 	`outcome_`phase'', ///
					over(Intro_D2, label(angle(45))) scale(*.8) stack percent blabel(bar, position(inside) format(%9.0f)) ///
					ytitle(Percent) title(`title_`phase'') ///
					bar(1,color(orange_red)) bar(2, color(gs14)) bar(3, color(gs8)) bar(4, color(midgreen)) ///
					legend( label(1 "Paid 0 %" ) label(2 "Paid 1-74 %") label(3 "Paid 75-99 %") label(4 "Paid 100 %")) ///
					graphr(c(white)) legend(rows(1) region(lwidth(none))) 
		graph export 	"Output\Appendix_FigureC1_Kit`val'_`phase'.png", as(png) replace
		}			
		
		
		

//FIGURE 4: PAYMENT OVER TIME BY PAYMENT SCHEME AND KIT
*Prepare data 
		*create buyer group variable
		egen 				buyergroup=concat(Type_kite I_liq1_scheme)
		replace				buyergroup="." if buyergroup==".1" | buyergroup==".2" | buyergroup==".3" /*these are hhs that did not win, i.e. buy anything*/
		destring 			buyergroup, replace
		label var			buyergroup "Buyer group" 
		label define		group 11 "Kit 1, 7 days" 12 "Kit 1, 6 weeks" 13 "Kit 1, 5 months" 21 "Kit 2, 7 days" 22 "Kit 2, 6 weeks" 23 "Kit 2, 5 months" 31 "Kit 3, 7 days" 32 "Kit 3, 6 weeks" 33 "Kit 3, 5 months"
		label val			buyergroup group
		gen 				Observations=.
		foreach var 		in 11 12 13 21 22 23 31 32 33 { /*save number of observations to display in graph*/
		tab 				buyergroup if buyergroup==`var' 
		replace				Observations=`r(N)' if buyergroup==`var'
		}

		
		save "WTP_storage.dta", replace /*save before data is collapsed*/

		*collapse, transpose, clean 
		collapse 			acc_daily* Observations, by(buyergroup)
		xpose, 				clear
		rename 				(v1 v2 v3 v4 v5 v6 v7 v8 v9) (Type11 Type12 Type13 Type21 Type22 Type23 Type32 Type33 Type31)
		drop if 			Type11==11
		gen 				day=_n
		label var 			day "Number of days since purchase"
		foreach var 		in 11 12 13 21 22 23 31 32 33 { /*to display in graph*/
		gen					Observation`var'_help=Type`var' if day==421
		egen 				Observation`var'=max(Observation`var'_help)
		}
		drop 				if day==421
		replace				Observation31=0 if Observation31==. 

		foreach kit in 	1 2 3 {
		local				N= Observation`kit'1
		label var			Type`kit'1 "Payment period: 1 week (N=`N')" /*to label graph*/
		local				N= Observation`kit'2
		label var			Type`kit'2 "Payment period: 6 weeks (N=`N')"
		local				N= Observation`kit'3
		label var			Type`kit'3 "Payment period: 5 months (N=`N')"
		}
		
*Output Figure F1
		foreach 			kit in 1 2 3{
		quietly line 		Type`kit'1 Type`kit'2 Type`kit'3 day, title(Payments over time for Kit `kit') ///
																	clpattern(line dash shortdash) lcolor(black gray ltblue) ///
																	clwidth (thin medium thick) ///
																	ytitle(Share of drawn price paid) ///
																	xtitle(Days since purchase) ///
																	graphr(c(white)) graphr(fc(white)) ///
																	legend(region(lwidth(none)) cols(1)) ///
																	legend( ) ///
																	yscale(r(0 100)) ///
																	xline(7, lpattern(dot)) xline(42, lpattern(dot)) xline(150.5, lpattern(dot)) ///
																	text(4 7  "7 days", size(small) c(grey) orientation(vertical)) ///
																	text(5 42  "6 weeks", size(small) c(grey) orientation(vertical)) ///
																	text(6 150.5  "5 months", size(small) c(grey) orientation(vertical))
		graph export 	"Output\Main_Figure4_Kit`kit'.png", as(png) replace
		}
	
		use "WTP_storage.dta", clear
		drop 	acc_daily*	Observations	

						
						
						
						




********************************************************************************************************************************
***************************************** Section 6.2  *************************************************************************
********************************************************************************************************************************

//Robustness checks: Prepare data for Section 6.2. (1. Adjust WTP for default, 2. Adjust WTP for decline, 3. Adjust WTP for default and decline) 
*Prepare data 

		*** 1. Predict default and generate adjusted WTP 
		************************************************
		*Prepare data for Imputation of shares paid in two periods (monitoring and deadline) for non-buyers
		foreach 			kit in 1 2 3 {
		gen 				share_deadlin_Kit`kit'=	. 
		replace 			share_deadlin_Kit`kit'=	share_paid_deadline if Kit_bought==`kit'
		gen 				share_moni_Kit`kit'=	. 
		replace 			share_moni_Kit`kit'=	share_paid5 if Kit_bought==`kit'	
		label var			share_deadlin_Kit`kit' "Share paid by deadline Kit `kit' predicted"
		label var			share_moni_Kit`kit' 	"Share paid by monitoring end Kit `kit' predicted"
		}
		
		*Output Imputation of shares paid (in two different time periods; paper only uses monitoring period) for non-buyers 
		local controls2 	date i.Intro_D dum_female_respondent hoh_years_edu hh_size dum_hoh_farmer share_member_student dum_roof_tile tot_ne_exp_month_USD  
		local controls3 	expen_phone_month_USD 	energy_exp_month_USD Q611a lamp_rec I_exp1_haskitlampSHS 
		
		foreach		kit in 1 2 3 { 
		foreach 	outcome in share_deadlin_Kit`kit' share_moni_Kit`kit'  {
		reg			`outcome' WTP_Kit`kit'_IR_raw_control3 Q120_USD_`kit' ib1.I_liq1_scheme `controls2' `controls3', vce(cluster Intro_D)
		predict		`outcome'_p
		replace 	`outcome'_p=`outcome' if `outcome'!=.  /*replace by real value for buyers'*/	
		replace		`outcome'_p=100 	if `outcome'_p>100 & `outcome'_p!=.
		replace		`outcome'_p=0 		if `outcome'_p<0
		}
		}
		
		*Alternative - don't predict with payment schemes: Output Imputation of shares paid for non-buyers 
		local controls2 	date i.Intro_D dum_female_respondent hoh_years_edu hh_size dum_hoh_farmer share_member_student dum_roof_tile tot_ne_exp_month_USD  
		local controls3 	expen_phone_month_USD 	energy_exp_month_USD Q611a lamp_rec I_exp1_haskitlampSHS 
		
		foreach		kit in 1 2 3 { 
		reg			share_moni_Kit`kit' WTP_Kit`kit'_IR_raw_control3 Q120_USD_`kit' `controls2' `controls3', vce(cluster Intro_D)
		predict		share2_moni_Kit`kit'_p
		replace 	share2_moni_Kit`kit'_p=share_moni_Kit`kit' if share_moni_Kit`kit'!=.  /*replace by real value for buyers'*/	
		replace		share2_moni_Kit`kit'_p=100 	if share2_moni_Kit`kit'_p>100 & share_moni_Kit`kit'_p!=.
		replace		share2_moni_Kit`kit'_p=0 		if share2_moni_Kit`kit'_p<0
		}
		
		
		*generate WTP adjusted for defaulting  for buyers and non-buyers (Kit 1 + Kit 2)
		tab				Kit_bought, gen(bought_kit)																						//generate dummy for type of kit bought
		foreach kit in 1 2 3 {																											//create three groups*/
		gen 			buyer_IR_kit`kit'		= 1 if bought_kit`kit'==1
		label var		buyer_IR_kit`kit'		"HH buys Kit `kit'"
		gen 			nonbuyer_IR_kit`kit'	= 1 if bought_kit`kit'!=1
		label var 		nonbuyer_IR_kit`kit'	"HH does not buy Kit `kit'"
		}			
		foreach 		kit in 1 2 {
		gen				WTP_Kit`kit'_IR_moni= 	(WTP_Kit`kit'_IR_raw_control3*share_moni_Kit`kit'_p)/100 				 				//generate WTP with share value effectively paid within monitoring phase* bid made
		label var 		WTP_Kit`kit'_IR_moni 	"Default-adjusted WTP Kit`kit'in monitoring phase"
		}
		*for Kit 3 seperately as values cannot be predicted for non-buyers due to small sample sizes of buyers
		gen				WTP_Kit3_IR_moni= 	(WTP_Kit3_IR_raw_control3*share_moni_Kit3_p)/100 	if buyer_IR_kit3==1 				 				
		label var 		WTP_Kit3_IR_moni 	"Default-adjusted WTP Kit3 monitoring phase"

		

		 
		*** 2. Predict declining and gen adjusted WTP 
		*********************************************
		*generate decline dummies 
		foreach 		kit in 1 2 3 {														
		gen				decline_kit`kit'				=0 if winchose`kit'==1 
		label var		decline_kit`kit' 				"declines to purchase Kit `kit'"
		replace			decline_kit`kit'				=1 if winchose`kit'==1 & winchosebuy`kit'==.
		replace 		dum_sale`kit'					=0 if dum_sale`kit'==.
		}
	
		*generate informationon favorite kit for nonwinners 
		foreach 		var in 1 2 3 {
		gen				Xfavo_`var'=0 
		replace			Xfavo_`var'=1 if  Q6==`var' 
		label var		Xfavo_`var' "Favorite kit of full sample"
		}

		*Estimate likelihood to decline purchase
		local controls2 	date i.Intro_D dum_female_respondent hoh_years_edu hh_size dum_hoh_farmer share_member_student dum_roof_tile tot_ne_exp_month_USD  
		local controls3 	expen_phone_month_USD 	energy_exp_month_USD Q611a lamp_rec I_exp1_haskitlampSHS 
		
		foreach			kit in 1 2 3 { 
		reg				decline_kit`kit' WTP_Kit`kit'_IR_raw_control3 Q120_USD_`kit' Xfavo_`kit' ib1.I_liq1_scheme `controls2' `controls3' if        winchose`kit'==1, vce(cluster Intro_D) //use only those that won the kit
		predict			decline_kit`kit'_p
		label var		decline_kit`kit'_p "Predicted likelihood to decline purchase for decliners and buyers"
		}
		
		foreach 		kit in 1 2 {
		bysort 			decline_kit`kit': tab decline_kit`kit'_p if winchose`kit'==1, miss
		tab 			decline_kit`kit'_p if winchose`kit'!=1
		}

		*Estimate likelihood to decline purchase (without payment schemes as predictors)
		local controls2 	date i.Intro_D dum_female_respondent hoh_years_edu hh_size dum_hoh_farmer share_member_student dum_roof_tile tot_ne_exp_month_USD  
		local controls3 	expen_phone_month_USD 	energy_exp_month_USD Q611a lamp_rec I_exp1_haskitlampSHS 
		
		foreach			kit in 1 2 3 { 
		reg				decline_kit`kit' WTP_Kit`kit'_IR_raw_control3 Q120_USD_`kit' Xfavo_`kit' `controls2' `controls3' if        winchose`kit'==1, vce(cluster Intro_D) //use only those that won the kit
		predict			decline2_kit`kit'_p
		label var		decline2_kit`kit'_p "Without payment scheme - Predicted likelihood to decline purchase for decliners and buyers"
		}
		
		foreach 		kit in 1 2 {
		bysort 			decline_kit`kit': tab decline_kit`kit'_p if winchose`kit'==1, miss
		tab 			decline_kit`kit'_p if winchose`kit'!=1
		}
		
		
		*gen decline-adjusted WTP for different scenarios (WTP is assumed to be different fractions of submitted bid) 
		foreach	level 	in 10 20 30 40 50 60 70 75 80 90 100 { 
		foreach var 	in 1 2 3 {
		
		gen				WTP_dec_`var'_85_`level'=.
		label var		WTP_dec_`var'_85_`level' 	"Decline-adjusted WTP:Kit`var'; 15% hypoth. decliners; replaced with `level'%of WTP"
				
		egen			cutoff_`var'_85_`level'= 	pctile(decline_kit`var'_p) if winchose`var'==., p(85) 															//generate cutoff point of 10,20 and 30 percent highest probability to decline; only generate for the sample that did not win the kit  
		label var		cutoff_`var'_85_`level' 	"Decline-Cutoff for 15% with highest likelihood to decline Kit`var'"
		egen			cutoff2_`var'_85_`level'= 	pctile(decline2_kit`var'_p) if winchose`var'==., p(85) 															//generate cutoff point of 10,20 and 30 percent highest probability to decline; only generate for the sample that did not win the kit  
		label var		cutoff2_`var'_85_`level' 	"without payment scheme: Decline-cutoff for 15% with highest likelihood to decline Kit`var'"
		replace			WTP_dec_`var'_85_`level'=	`level'*WTP_Kit`var'_IR_raw_control3/100 if decline_kit`var'_p>=cutoff_`var'_85_`level' & winchose`var'==. 	//replace WTP value by 0/10/20/30 etc % of actual WTP if falls below the highest likelihood to decline and did not win 
		replace			WTP_dec_`var'_85_`level'=	WTP_Kit`var'_IR_raw_control3 if winchose!=. & winchosebuy!=. 													//use WTP from bidding game for winners that actually buy for all percentage settings
		replace			WTP_dec_`var'_85_`level'=	WTP_Kit`var'_IR_raw_control3 if decline_kit`var'_p<cutoff_`var'_85_`level' & winchose`var'==.					//use WTP from bidding game for non-winners with low likelihood to decline 
		replace			WTP_dec_`var'_85_`level'=	`level'*WTP_Kit`var'_IR_raw_control3/100 if decline_kit`var'==1														//set WTP equal to 0/10/20/30 etc % of actual WTP among decliners 
		}
		replace			WTP_dec_3_85_`level'=. if winchose3==. 		//predictions for Kit 3 should not be used, as regression is based on very small N and did not fully run
		}
		
		*generate median decline-adjusted WTP 
		foreach	level 	in 10 20 30 40 50 60 70 75 80 90 100 { 
		foreach var in 1 2 3 {
		qui sum 		WTP_dec_`var'_85_`level', 			det
		gen				med_WTP_dec_`var'_85_`level'= 		`r(p50)'
		label var 		med_WTP_dec_`var'_85_`level' 		"MEDIAN decline adjusted WTP (85%; level:`level'%)"
		}
		}


		*gen decline-adjusted WTP as share of monthly expenditures (mean and median) 
		foreach 		x in 50  {														//here generate only for scenario of 50 percent (true WTP of decliners is 50% of submitted bid). Can generate share for other scenarios by adding them here in loop (10 20 30 40 50 60 70 80 90 100)
		foreach kit in 	1 2 3 {
		foreach var 	in WTP_dec_`kit'_85_`x' {  
		gen 			share_exp_`var'=(`var'*100)/ total_exp_month_nowood_USD		//gen mean
		label var 		share_exp_`var' "Mean decline-adjusted WTP Kit`kit' as share mntl expenditures"
		sum 			share_exp_`var', detail
		gen 			med_share_exp_`var'= `r(p50)'											//gen median 
		label var 		med_share_exp_`var' "Median decline-adjusted WTP Kit`kit' as share mntl expenditures"
		}
		}	
		}
		
		*** 3. Generate WTP adjusted for decline AND default
		*****************************************
		*generate adjusted WTP where decliners and hypothetical decliners are set to 50% of bid, buyers are set to their effective payment, hypothetical buyers are set to their hypothetical payment 
		foreach 		var in 1 2 3	{
		clonevar		WTP_dr_`var'_85_50=WTP_dec_`var'_85_50
		label var		WTP_dr_`var'_85_50 "Decline+defalut adjusted WTP (85%; level:50%)"
		replace			WTP_dr_`var'_85_50=WTP_Kit`var'_IR_moni if winchosebuy`var'==1 												//replace by effective WTP (value that was paid) if bought the kit 
		replace			WTP_dr_`var'_85_50=WTP_Kit`var'_IR_moni if decline_kit`var'_p<cutoff_`var'_85_50 & winchose`var'==.			//replace by hypothetical effective WTP if did not win and IF HAD NOT BEEN REPLACED BY 10% WTP DUE TO HH'S HIGH LIKELIHOOD TO decline
		}
		replace			WTP_dr_3_85_50=. if winchosebuy3!=1
		
		
		*gen share in monthly expenditure: (non-adjusted) bid
		*Kit 1 and 2 
		foreach 		var in 1 2  {
		gen				share_exp_WTP_Kit`var'= 			(WTP_Kit`var'_IR_raw_control3*100)/ total_exp_month_nowood_USD 				if WTP_Kit`var'_IR_raw_control3!=. & total_exp_month_nowood_USD!=. 
		label var 		share_exp_WTP_Kit`var' 				"WTP Kit `var': share mntl expenditures"
		qui sum			share_exp_WTP_Kit`var', det
		gen				med_share_exp_WTP_Kit`var'=`r(p50)'
		label var		med_share_exp_WTP_Kit`var' 			"WTP Kit `var': MEDIAN share mntl expend"
		}
		*Kit 3
		gen				share_exp_WTP_Kit3= 				(WTP_Kit3_IR_raw_control3*100)/ total_exp_month_nowood_USD 					if winchosebuy3!=. 
		label var 		share_exp_WTP_Kit3 					"WTP Kit 3: share mntl expenditures - only buyer"
		qui sum			share_exp_WTP_Kit3, det
		gen				med_share_exp_WTP_Kit3=`r(p50)'																				if winchosebuy3!=.
		label var 		med_share_exp_WTP_Kit3				"WTP Kit3: MEDIAN share mntl expenditures"
			
		
		*gen share in monthly expenditures: decline+defalut adjusted WTP as share of expenditures
		*Kit 1 and 2
		foreach kit 	in 1 2 {
		foreach var 	in WTP_dr_`kit'_85_50 	{  
		gen 			share_exp_`var'=		(`var'*100)/ total_exp_month_nowood_USD		//gen mean
		label var 		share_exp_`var' 		"Decline+default adjusted WTP Kit`kit': share mnthl expend"	
		sum 			share_exp_`var', 		detail
		gen 			med_share_exp_`var'= 	`r(p50)' 									//gen median 
		label var 		med_share_exp_`var' 	"Decline+default adjusted WTP Kit`kit': MEDIAN share mnthl expend"
		}
		}
		*Kit 3 only default-adjusted
		gen 			share_exp_WTP_Kit_3_moni=			(WTP_Kit3_IR_moni*100)/ total_exp_month_nowood_USD	if winchosebuy3!=.	//gen mean
		label var 		share_exp_WTP_Kit_3_moni 			"Default adjusted WTP Kit3: share mnthl expend - buyers only"	
		sum 			share_exp_WTP_Kit_3_moni, 			detail
		gen 			med_share_exp_WTP_Kit_3_moni= 		`r(p50)' 											if winchosebuy3!=. 	//gen median 
		label var 		med_share_exp_WTP_Kit_3_moni		"Default adjusted WTP Kit3: MEDIAN share mnthl expend"

				
				
//Figure 5: SENSITIVITY OF WILLIGNESS TO PAY TO DECLINERS (in USD) 
*Prepare data
	foreach 			kit in 1 2   {
	foreach var 		in 10 20 30 40 50 60 70 80 90 100 {
	preserve
	collapse (mean) 	WTP_Kit`kit'_IR_raw_control3 (mean) med_WTP_dec_`kit'_85_`var' (mean) WTP_dec_`kit'_85_`var' (median) medWTP_dec_`kit'_85_`var'=WTP_dec_`kit'_85_`var' (median) medWTP_Kit`kit'_IR_raw_control3=WTP_Kit`kit'_IR_raw_control3
	rename 				WTP_dec_`kit'_85_`var' mean
	rename 				medWTP_dec_`kit'_85_`var' median
	label var mean 	adjusted_mean
	label var median 	adjusted_median

	rename 				WTP_Kit`kit'_IR_raw_control3 original_mean
	rename 				medWTP_Kit`kit'_IR_raw_control3 original_median
	label var 			original_mean original_mean
	label var 			original_median original_median

	gen 				ID=`var'
	save  				"`kit'_85_`var'.dta", replace
	restore
	}
	}

*Output Figure 5 Kit 1 
	preserve

	use "1_85_10.dta", clear
	append using  "1_85_20.dta"
	append using  "1_85_30.dta"
	append using  "1_85_40.dta"
	append using  "1_85_50.dta"
	append using  "1_85_60.dta"
	append using  "1_85_70.dta"
	append using  "1_85_80.dta"
	append using  "1_85_90.dta"
	append using  "1_85_100.dta"

	twoway (line mean ID, lcolor(black) lwidth(thick) lpattern(solid)) ///
	(line median ID, lcolor(black) lwidth(thick) lpattern(longdash)) ///
	(line original_mean ID, lcolor(gs9)  lwidth(thin) lpattern(solid)) ///
	(line original_median ID, lcolor(gs9) lwidth(thin) lpattern(longdash)) ///
	, ylabel(#5, nogrid) graphr(c(white)) yscale(range(3.4 5)) ///
	xtitle(decliners' true WTP at  % of bid) ///
	ytitle(Adjusted WTP) ///
	legend(region(lwidth(none)) cols(1) label(1 "Mean adjusted WTP") label(2 "Median adjusted WTP") label(3 "Mean Bid") label(4 "Median Bid"))
	graph export "Output\Figure5_decliner_WTP_Kit1.png", as(png) replace

	restore

*Output Figure 5 Kit 2
	preserve

	use "2_85_10.dta", clear
	append using  "2_85_20.dta"
	append using  "2_85_30.dta"
	append using  "2_85_40.dta"
	append using  "2_85_50.dta"
	append using  "2_85_60.dta"
	append using  "2_85_70.dta"
	append using  "2_85_80.dta"
	append using  "2_85_90.dta"
	append using  "2_85_100.dta"

	twoway (line mean ID, lcolor(black) lwidth(thick) lpattern(solid)) ///
	(line median ID, lcolor(black) lwidth(thick) lpattern(longdash)) ///
	(line original_mean ID, lcolor(gs9)  lwidth(thin) lpattern(solid)) ///
	(line original_median ID, lcolor(gs9) lwidth(thin) lpattern(longdash)) ///
	, ylabel(#5, nogrid) graphr(c(white)) yscale(range(3.4 16.5)) ///
	ytitle(Adjusted WTP) ///
	xtitle(decliners' true WTP at  % of bid) ///
	legend(region(lwidth(none)) cols(1) label(1 "Mean adjusted WTP") label(2 "Median adjusted WTP") label(3 "Mean Bid") label(4 "Median Bid"))
	graph export "Output\Figure5_decliner_WTP_Kit2.png", as(png) replace

	restore

	*drop variables that will not be needed anymore 
	foreach 	kit in 1 2  {
	foreach 	level in 20 30 40 50 60 70 80 90 100 {		//cutoffs 10 will be needed below for Table 9, therefore do not drop here. 
	erase  		"`kit'_85_`level'.dta"
	drop		med_WTP_dec_`kit'_85_`level'
	drop		WTP_dec_`kit'_85_`level'
	drop		cutoff_`kit'_85_`level'
	}
	}
	
	

//Table 7: Adjusted willigness to pay vs bid for Kit 1 (in USD)
*Prepare data 
		*Create medians for output for Kit 1 WTP 
		foreach var in WTP_Kit1_IR_raw_control3 WTP_Kit1_IR_moni WTP_dr_1_85_50 bid1_exp_share_IR share_exp_WTP_dr_1_85_50 {	
		qui sum 	`var', det
		gen			`var'_med= `r(p50)'			 
		local		l`var': variable label `var'
		label var	`var'_med "Median `l`var''"
		}
	
		*Create medians for output for Kit 2 WTP 
		foreach var in WTP_Kit2_IR_raw_control3 WTP_Kit2_IR_moni WTP_dr_2_85_50 bid2_exp_share_IR share_exp_WTP_dr_2_85_50 {	
		qui sum 	`var', det
		gen			`var'_med= `r(p50)'			 
		local		l`var': variable label `var'
		label var	`var'_med "Median `l`var''"
		}

*Output	
		*Kit 1
		asdoc sum 	 WTP_Kit1_IR_raw_control3 WTP_Kit1_IR_raw_control3_med WTP_Kit1_IR_moni WTP_Kit1_IR_moni_med WTP_dr_1_85_50 WTP_dr_1_85_50_med bid1_exp_share_IR bid1_exp_share_IR_med share_exp_WTP_dr_1_85_50 share_exp_WTP_dr_1_85_50_med,	/// 
										save(Output\Main_Section6.2_Table7.doc) /// 
										append ///
										label ///
										dec(1) ///
										stat(mean) ///
										title(Adjusted willingness to pay for Kit 1 in USD)

		*drop medians that were created for output
		drop WTP_Kit1_IR_raw_control3_med WTP_Kit1_IR_moni_med WTP_dr_1_85_50_med bid1_exp_share_IR_med share_exp_WTP_dr_1_85_50_med bid1_exp_share_IR_med share_exp_WTP_dr_1_85_50_med
	
		*Kit 2
		asdoc sum 	 WTP_Kit2_IR_raw_control3 WTP_Kit2_IR_raw_control3_med WTP_Kit2_IR_moni WTP_Kit2_IR_moni_med WTP_dr_2_85_50 WTP_dr_2_85_50_med bid2_exp_share_IR bid2_exp_share_IR_med share_exp_WTP_dr_2_85_50 share_exp_WTP_dr_2_85_50_med,	/// 
										save(Output\Main_Section6.2_Table7.doc) /// 
										append ///
										label ///
										dec(1) ///
										stat(mean) ///
										title(Adjusted willingness to pay for Kit 1 in USD)

		*drop medians that were created for output
		drop WTP_Kit2_IR_raw_control3_med WTP_Kit2_IR_moni_med WTP_dr_2_85_50_med bid2_exp_share_IR_med share_exp_WTP_dr_2_85_50_med bid2_exp_share_IR_med share_exp_WTP_dr_2_85_50_med
				
	
//Table 8: Adjusted willigness to pay vs bid for buyers of Kit 3 (in USD)
*Prepare data 
		*Create medians for output of WTP for Kit 3 by buyers only 
		foreach var in WTP_Kit3_IR_raw_control3 WTP_Kit3_IR_moni share_exp_WTP_Kit3 share_exp_WTP_Kit_3_moni {	
		qui sum 	`var' if buyer_IR_kit3==1, det
		gen			`var'_med= `r(p50)' if buyer_IR_kit3==1 			 
		local		l`var': variable label `var'
		label var	`var'_med "Median `l`var''"
		}
		
		*Create medians for output of WTP for Kit 3 by full sample for comparison
		foreach var in WTP_Kit3_IR_raw_control3  bid3_exp_share_IR share_exp_WTP_Kit_3_moni {							 
		qui sum 	`var', det					
		gen			`var'_med2= `r(p50)' 								 
		local		l`var': variable label `var'
		label var	`var'_med2 "Median `l`var''"
		}
		
*Output	
		*Buyer sample 
		asdoc sum 	WTP_Kit3_IR_raw_control3 WTP_Kit3_IR_raw_control3_med WTP_Kit3_IR_moni WTP_Kit3_IR_moni_med share_exp_WTP_Kit3 share_exp_WTP_Kit3_med share_exp_WTP_Kit_3_moni share_exp_WTP_Kit_3_moni_med if buyer_IR_kit3==1,	/// 
										save(Output\Main_Section6.2_Table8.doc) /// 
										append ///
										label ///
										dec(1) ///
										stat(mean) ///
										title(Adjusted willingness for buyers of Kit 3 in USD)

		*drop medians that were created for output
		drop 	WTP_Kit3_IR_raw_control3_med WTP_Kit3_IR_moni_med share_exp_WTP_Kit3_med share_exp_WTP_Kit_3_moni_med

		*Full sample for comparison 
		asdoc sum 			WTP_Kit3_IR_raw_control3 WTP_Kit3_IR_raw_control3_med2 bid3_exp_share_IR bid3_exp_share_IR_med2,	/// 
										save(Output\Main_Section6.2_Table8.doc) /// 
										append ///
										label ///
										dec(1) ///
										stat(mean) ///
										title(Bid for Kit 3 of full sample in USD)
		
		*drop medians that were created for output
		drop WTP_Kit3_IR_raw_control3_med2 bid3_exp_share_IR_med2
		
		 










********************************************************************************************************************************
*********************************** Section 6.3 and corresponding appendix D ***************************************************
********************************************************************************************************************************
															

//Table 9: Payment periods and willigness to pay (controlling for defaulting and declining)
//Appendix Table D1: Payment periods and willingness to pay (controlling for defaulting and declining) 

*Prepare data
		**generate variable for defaulting 
		foreach 	kit in 1 2 {
		gen 		default_shareKit`kit'=share_moni_Kit`kit' //real defaulter
		replace 	default_shareKit`kit'=share_moni_Kit`kit'_p if default_shareKit`kit'==. //predicted values
		label var	default_shareKit`kit' "Defaultet share Kit `kit'_predict with payment scheme"
		gen 		default2_shareKit`kit'=share_moni_Kit`kit' //real defaulter
		replace 	default2_shareKit`kit'=share2_moni_Kit`kit'_p if default2_shareKit`kit'==. //predicted values (predicted without payment schemes)
		label var	default2_shareKit`kit' "Defaultet share Kit `kit'_predict without payment scheme"
		gen 		winner_default_shareKit`kit'=share_moni_Kit`kit' //real defaulter
		replace 	winner_default_shareKit`kit'=100 if winner_default_shareKit`kit'==. //assume non-winner don't default
		label var	winner_default_shareKit`kit' "Defaultet share Kit `kit'_assume nonwinners dont default"
		}
	
		**generate dummy for declining 
		foreach 	kit in 1 2 {
		gen 		decliner`kit'=0
		replace 	decliner`kit'=1 if decline_kit`kit'==1
		replace 	decliner`kit'=1 if decline_kit`kit'_p>cutoff_`kit'_85_10 & winchose`kit'==.
		label var 	decliner`kit' "HH declines kit `kit'_predicted with payment schemes"
		gen 		decliner2`kit'=0 //predicted without payment schemes
		replace 	decliner2`kit'=1 if decline_kit`kit'==1
		replace 	decliner2`kit'=1 if decline2_kit`kit'_p>cutoff2_`kit'_85_10 & winchose`kit'==.
		label var 	decliner2`kit' "HH declines kit `kit'_predicted without payment schemes"
		gen 		winner_decliner`kit'=0
		replace 	winner_decliner`kit'=1 if decline_kit`kit'==1 //assume that non-winners don't decline
		label var	winner_decliner`kit' "HH declines kit `kit'_assume nonwinners dont default"
		}
		
*Output Table 9 and Appendix Table D1 
		local controls1 	date i.Intro_D 
		local controls2 	date i.Intro_D dum_female_respondent  	hoh_years_edu hh_size dum_hoh_farmer share_member_student dum_roof_tile tot_ne_exp_month_USD  
		local controls3 	date i.Intro_D dum_female_respondent  	hoh_years_edu hh_size dum_hoh_farmer share_member_student dum_roof_tile tot_ne_exp_month_USD  expen_phone_month_USD 	energy_exp_month_USD Q611a lamp_rec I_exp1_haskitlampSHS 

		foreach kit 		in 1 2  {
		*original version
		intreg 			bid`kit'_USD bid`kit'_USD_ll ib1.I_liq1_scheme  `controls3', vce(robust) /*if no bid was made, the lower bound is equal to missing, the higher bound is equal to the lower bound. If a bid was made, both values are the same*/
		est store 			r_wo_3_`kit'		
		*control for default and declining
		intreg 			bid`kit'_USD bid`kit'_USD_ll ib1.I_liq1_scheme  default_shareKit`kit' decliner`kit' `controls3'  , vce(robust) /*if no bid was made, the lower bound is equal to missing, the higher bound is equal to the lower bound. If a bid was made, both values are the same*/
		est store 			r3_`kit' 
		*control for d & d (predicted without payment scheme
		intreg 			bid`kit'_USD bid`kit'_USD_ll ib1.I_liq1_scheme  default2_shareKit`kit' decliner2`kit' `controls3'  , vce(robust) /*if no bid was made, the lower bound is equal to missing, the higher bound is equal to the lower bound. If a bid was made, both values are the same*/
		est store 			r23_`kit' 
		*control for d & d (assume non-winners don't d & d)
		intreg 			bid`kit'_USD bid`kit'_USD_ll ib1.I_liq1_scheme  winner_default_shareKit`kit' winner_decliner`kit' `controls3'  , vce(robust) /*if no bid was made, the lower bound is equal to missing, the higher bound is equal to the lower bound. If a bid was made, both values are the same*/
		est store 			r_winner_3_`kit' 


		local				title 				"Table 9 and Appendix_TableD1: Payment periods and willingness to pay"
		local				file 				"Table9_Appendix_TableD1"
		local 				addnote 			"Note: We display coefficients from an IR estimation with robust standard errors. The dependent variable is log of WTP. The base category is a one-week payment period." 
		local				addtext_1			"Communty and Time, YES, Socio-economics, NO, Energy Consumption, NO, Mean WTP 7 days scheme, . "
		local				addtext_2			"Communty and Time, YES, Socio-economics, YES, Energy Consumption, NO, Mean WTP 7 days scheme, . "
		local				addtext_3			"Communty and Time, YES, Socio-economics, YES, Energy Consumption, YES, Mean WTP 7 days scheme, . " /*mean WTP values have to be added manually, as they are predicted and calculated only after this estimation*/
                   

	
		outreg2 			[r_wo_3_`kit'] using "Output\Main_Section 6.3_`file'.doc", 	append ///
																							label ///
																							nodepvar ///
																							nocons ///
																							bdec(3) ///
																							stats(coef pval) ///
																							drop(`controls1' `controls2' `controls3') ///
																							ctitle("Kit`kit'") ///	
																							asterisk(pval) ///
																							title("`title'") /// 	
																							addnote(`addnote' The values are bottom and top coded at 2 percent and 98 percent of the distribution respectively to eliminate the effect of outliers. 2 Excluding energy and phone charging expenditures. 3 Including expenditures on kerosene gas batteries candles and charcoal; excluding expenditures on wood and rechargeable lamp charging.) ///
																							addtext(`addtext_3') ///
																							eqdrop(lnsigma)

		outreg2 			[r3_`kit'] using "Output\Main_Section 6.3_`file'.doc", 	append ///
																							label ///
																							nodepvar ///
																							nocons ///
																							bdec(3) ///
																							stats(coef pval) ///
																							drop(`controls1' `controls2' `controls3') ///
																							ctitle("Kit`kit'") ///	
																							asterisk(pval) ///
																							title("`title'") /// 	
																							addnote(`addnote' The values are bottom and top coded at 2 percent and 98 percent of the distribution respectively to eliminate the effect of outliers. 2 Excluding energy and phone charging expenditures. 3 Including expenditures on kerosene gas batteries candles and charcoal; excluding expenditures on wood and rechargeable lamp charging.) ///
																							addtext(`addtext_3') ///
																							eqdrop(lnsigma)
		
		outreg2 			[r23_`kit'] using "Output\Main_Section 6.3_`file'.doc", 	append ///
																							label ///
																							nodepvar ///
																							nocons ///
																							bdec(3) ///
																							stats(coef pval) ///
																							drop(`controls1' `controls2' `controls3') ///
																							ctitle("Kit`kit'") ///	
																							asterisk(pval) ///
																							title("`title'") /// 	
																							addnote(`addnote' The values are bottom and top coded at 2 percent and 98 percent of the distribution respectively to eliminate the effect of outliers. 2 Excluding energy and phone charging expenditures. 3 Including expenditures on kerosene gas batteries candles and charcoal; excluding expenditures on wood and rechargeable lamp charging.) ///
																							addtext(`addtext_3') ///
																							eqdrop(lnsigma)
	
		outreg2 			[r_winner_3_`kit'] using "Output\Main_Section 6.3_`file'.doc", 	append ///
																							label ///
																							nodepvar ///
																							nocons ///
																							bdec(3) ///
																							stats(coef pval) ///
																							drop(`controls1' `controls2' `controls3') ///
																							ctitle("Kit`kit'") ///	
																							asterisk(pval) ///
																							title("`title'") /// 	
																							addnote(`addnote' The values are bottom and top coded at 2 percent and 98 percent of the distribution respectively to eliminate the effect of outliers. 2 Excluding energy and phone charging expenditures. 3 Including expenditures on kerosene gas batteries candles and charcoal; excluding expenditures on wood and rechargeable lamp charging.) ///
																							addtext(`addtext_3') ///
																							eqdrop(lnsigma)

							}
							
			
		*Drop 
		drop	_est_r*
		drop 	default_shareKit1 default2_shareKit1 winner_default_shareKit1 default_shareKit2 default2_shareKit2 winner_default_shareKit2 decliner1 decliner21 winner_decliner1 decliner2 decliner22 winner_decliner2
